【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

题目链接:

  http://codeforces.com/gym/100851

题目大意:

  一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和。C c取出第c列还未被取出的所有数并输出和。

题目思路:

  【模拟】

  首先Ai,j=i+j这个很关键。预处理每一行(=列)的值。

  只要记录当前取得时候前面已经取过的所有行数的和、次数,所有列数的和、次数,就能推算出这次取数会少掉多少值。

  并记录这一行或这一列被取过没有。

 1 //
 2 //by coolxxx
 3 //#include<bits/stdc++.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<map>
 9 #include<stack>
10 #include<queue>
11 #include<set>
12 #include<bitset>
13 #include<memory.h>
14 #include<time.h>
15 #include<stdio.h>
16 #include<stdlib.h>
17 #include<string.h>
18 //#include<stdbool.h>
19 #include<math.h>
20 #define min(a,b) ((a)<(b)?(a):(b))
21 #define max(a,b) ((a)>(b)?(a):(b))
22 #define abs(a) ((a)>0?(a):(-(a)))
23 #define lowbit(a) (a&(-a))
24 #define sqr(a) ((a)*(a))
25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
26 #define mem(a,b) memset(a,b,sizeof(a))
27 #define eps (1e-8)
28 #define J 10
29 #define mod 1000000007
30 #define MAX 0x7f7f7f7f
31 #define PI 3.14159265358979323
32 #define N 1000004
33 using namespace std;
34 typedef long long LL;
35 int cas,cass;
36 int n,m,lll,ans;
37 LL sum,tot,a,b;
38 LL c[N];
39 char s[2];
40 bool u[N],v[N];
41 int main()
42 {
43     #ifndef ONLINE_JUDGE
44 //    freopen("3.txt","r",stdin);
45 //    freopen("2.txt","w",stdout);
46     #endif
47     int i,j,k;
48 //    for(scanf("%d",&cass);cass;cass--)
49 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
50 //    while(~scanf("%s",s+1))
51     while(~scanf("%d",&n))
52     {
53         sum=tot=a=b=0;mem(u,0);mem(v,0);
54         scanf("%d",&m);
55         c[1]=1LL*(2+1+n)*n/2;
56         for(i=2;i<=n;i++)c[i]=c[i-1]+n;
57         for(i=1;i<=m;i++)
58         {
59             scanf("%s%d",s,&cas);
60             if(s[0]==‘R‘)
61             {
62                 if(u[cas]){puts("0");continue;}
63                 printf("%I64d\n",c[cas]-tot-b*cas);
64                 sum+=cas;
65                 a++;
66                 u[cas]=1;
67             }
68             else
69             {
70                 if(v[cas]){puts("0");continue;}
71                 printf("%I64d\n",c[cas]-sum-a*cas);
72                 tot+=cas;
73                 b++;
74                 v[cas]=1;
75             }
76         }
77     }
78     return 0;
79 }
80 /*
81 //
82
83 //
84 */

时间: 2024-08-05 08:32:34

【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)的相关文章

HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 802    Accepted Submission(s): 309 Problem Description A mysterious country will hold a football world championships---Abnormal Cup

2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5984 Pocky 题意 给出一根棒子(可以吃的)的长度x和切割过程中不能小于的长度d,每次随机的选取一个位置切开,吃掉左边的一半,对右边的棒子同样操作,直至剩余的长度不大于d时停止.现在给出x和d,问切割次数的数学期望是多少. 解题思路 当看到第二个样例2 1时,结果是1.693147,联想到ln

2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp

odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 388    Accepted Submission(s): 212 Problem Description For a number,if the length of continuous odd digits is even and the length

hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 208    Accepted Submission(s): 101 Problem Description You may not know this but it's a fact that Xinghai Square is

HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 997    Accepted Submission(s): 306 Problem Description The empire is under attack again. The general of empire is planning to defend his

2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元

hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 802    Accepted Submission(s): 269 Problem Description hannnnah_j is a teacher in WL High school who teaches biolog

2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp

QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 859    Accepted Submission(s): 325 Problem Description Every school has some legends, Northeastern University is the same. Enter

2016 ACM/ICPC Asia Regional Dalian Online 1002/HDU 5869

Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 681    Accepted Submission(s): 240 Problem Description This is a simple problem. The teacher gives Bob a list of prob

2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873

Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 439    Accepted Submission(s): 157 Problem Description A mysterious country will hold a football world championships---Abnormal Cup

2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 782    Accepted Submission(s): 406 Problem Description I will show you the most popular board game in the Shanghai Ingress Resis