Adjustment OfficeInput file: adjustment.inOutput file: adjustment.outGarrison and Anderson are working in a company named “Adjustment Office”. In competing companiesworkers change the reality, in this company they try to predict the future.They are given a big square board n × n. Initially in each cell (x, y) of this board the value of x + y iswritten (1 ≤ x, y ≤ n). They know that in the future there will be two types of queries on the board:• “R r” — sum up all values in row r, print the result and set all values in row r to zero;• “C c” — sum up all values in column c, print the result and set all values in column c to zero.They have predicted what queries and results there will be. They need to ensure that they have correctlypredicted the results. Help them by computing the results of the queries.InputThe first line of the input contains two integers n and q (1 ≤ n ≤ 106, 1 ≤ q ≤ 105) — the size of thesquare and the number of queries.Each of the next q lines contains the description of the query. Each query is either “R r” (1 ≤ r ≤ n) or“C c” (1 ≤ c ≤ n).OutputThe output file shall contain q lines. The i-th line shall contain one integer — the result of the i-th query.Sample input and outputadjustment.in adjustment.out3 7R 2C 3R 2R 1C 2C 1R 3121005540Page 1 of 14ACM ICPC 2015Problem
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
using namespace std;
long long int r[1000005]={0},c[1000005]= {0};
int main()
{
freopen("adjustment.in","r",stdin);
freopen("adjustment.out","w",stdout);
long long int n,t;
scanf("%lld%lld",&n,&t);
long long int sum,rrr,ccc,rr,cc;
sum=rrr=ccc=0;
rr=cc=0;
char s;
bool flag=0;
if(n%2==0)
flag=1;
while(t--)
{
sum=0;
getchar();
long long data;
scanf("%c %lld", &s, &data);
if(s=='R')
{
if(r[data]!=0)
{
printf("0\n");
continue;
}
sum-=rrr;
sum+=data*(n-rr);
if(flag)
sum+=(n/2)*(n+1);
else
sum+=(n)*((n+1)/2);
r[data]=1;
ccc+=data;
cc++;
printf("%lld\n",sum);
}
if(s =='C')
{
if(c[data]!=0)
{
printf("0\n");
continue;
}
sum-=ccc;
sum+=data*(n-cc);
if(flag)
sum+=(n/2)*(n+1);
else
sum+=(n)*((n+1)/2);
c[data]=1;
rrr+=data;
rr++;
cout<<sum<<endl;
}
}
return 0;
}