Adjustment OfficeInput file

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值