您的位置:首页 > 其它

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

2016-08-30 15:57 543 查看
题目链接:

  http://codeforces.com/gym/100851


题目大意:

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

题目思路:

  【模拟】

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

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

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

//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 1000004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
LL sum,tot,a,b;
LL c
;
char s[2];
bool u
,v
;
int main()
{
#ifndef ONLINE_JUDGE
//    freopen("3.txt","r",stdin);
//    freopen("2.txt","w",stdout);
#endif
int i,j,k;
//    for(scanf("%d",&cass);cass;cass--)
//    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
//    while(~scanf("%s",s+1))
while(~scanf("%d",&n))
{
sum=tot=a=b=0;mem(u,0);mem(v,0);
scanf("%d",&m);
c[1]=1LL*(2+1+n)*n/2;
for(i=2;i<=n;i++)c[i]=c[i-1]+n;
for(i=1;i<=m;i++)
{
scanf("%s%d",s,&cas);
if(s[0]=='R')
{
if(u[cas]){puts("0");continue;}
printf("%I64d\n",c[cas]-tot-b*cas);
sum+=cas;
a++;
u[cas]=1;
}
else
{
if(v[cas]){puts("0");continue;}
printf("%I64d\n",c[cas]-sum-a*cas);
tot+=cas;
b++;
v[cas]=1;
}
}
}
return 0;
}
/*
//

//
*/


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐