結果

問題 No.2338 Range AtCoder Query
ユーザー momoyuumomoyuu
提出日時 2023-06-03 00:17:27
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 850 ms / 4,000 ms
コード長 3,269 bytes
コンパイル時間 4,621 ms
コンパイル使用メモリ 256,988 KB
実行使用メモリ 22,856 KB
最終ジャッジ日時 2023-08-28 06:57:14
合計ジャッジ時間 23,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,804 KB
testcase_01 AC 5 ms
11,828 KB
testcase_02 AC 4 ms
11,840 KB
testcase_03 AC 5 ms
11,788 KB
testcase_04 AC 5 ms
11,964 KB
testcase_05 AC 5 ms
11,796 KB
testcase_06 AC 7 ms
11,896 KB
testcase_07 AC 6 ms
12,060 KB
testcase_08 AC 8 ms
11,792 KB
testcase_09 AC 7 ms
11,816 KB
testcase_10 AC 8 ms
11,896 KB
testcase_11 AC 636 ms
18,064 KB
testcase_12 AC 598 ms
18,112 KB
testcase_13 AC 654 ms
18,152 KB
testcase_14 AC 612 ms
18,116 KB
testcase_15 AC 750 ms
18,748 KB
testcase_16 AC 850 ms
20,576 KB
testcase_17 AC 844 ms
20,516 KB
testcase_18 AC 835 ms
20,524 KB
testcase_19 AC 837 ms
20,560 KB
testcase_20 AC 841 ms
20,520 KB
testcase_21 AC 828 ms
20,708 KB
testcase_22 AC 843 ms
20,592 KB
testcase_23 AC 832 ms
20,524 KB
testcase_24 AC 842 ms
20,588 KB
testcase_25 AC 843 ms
20,480 KB
testcase_26 AC 64 ms
18,192 KB
testcase_27 AC 60 ms
18,176 KB
testcase_28 AC 63 ms
18,204 KB
testcase_29 AC 552 ms
20,424 KB
testcase_30 AC 849 ms
20,564 KB
testcase_31 AC 566 ms
22,856 KB
testcase_32 AC 501 ms
21,320 KB
testcase_33 AC 405 ms
20,560 KB
testcase_34 AC 402 ms
20,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int mx = 2e5+10;
int nnn[mx],now[mx],l[mx],r[mx],ccc[mx],cnc[mx],nxt[mx];
int p[mx];
int n,m,q;
const int B = 600;
char s[mx];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>n>>m>>q;
    for(int i = 0;i<n;i++){
        cin>>p[i];
        string a;
        cin>>a;
        if(a=="AC") s[i] = 1;
    }
    int mx = 2e5;
    vector<vector<int>> is(mx+1);
    for(int i = 0;i<n;i++){
        is[p[i]].push_back(i);
    }
    for(int i = 0;i<=mx;i++){
        int now = 0;
        int ni = -1;
        if(is[i].size()==0) continue;
        for(int j = is[i].size()-1;j>=0;j--){
            if(s[is[i][j]]){
                cnc[is[i][j]] = now;
                nxt[is[i][j]] = ni;
                now= 0;
                ni = is[i][j];
            }else{
                now++;
            }
        }
    }
    for(int i = 0;i<q;i++){
        cin>>l[i]>>r[i];
        l[i]--;
    }
    vector<int> idx(q);
    for(int i = 0;i<q;i++) idx[i] = i;
    sort(idx.begin(),idx.end(),[&](int i,int j){
        if(l[i]/B!=l[j]/B) return l[i] < l[j];
        if(l[i]/B%2) return r[i] > r[j];
        return r[i] < r[j];
    });
    int ans = 0;
    int cnt = 0;
    int nl = 0;
    int nr = 1;
    vector<pair<int,int>> aa(q);
    if(s[0]){
        ans++;
        nnn[p[0]]++;
        now[p[0]]++;
    }else{
        now[p[0]]++;
    }
    for(int i = 0;i<q;i++){
        int ni = idx[i];
        while(l[ni]<nl){
            nl--;
            if(s[nl]){
                cnt -= ccc[p[nl]];
                ccc[p[nl]]=0;
                nnn[p[nl]]++;
                if(nnn[p[nl]]==1) ans++;
                now[p[nl]]++;
            }else{
                if(nnn[p[nl]]){
                    cnt++;
                    ccc[p[nl]]++;
                }
                now[p[nl]]++;
            }
        }
        while(nr<r[ni]){
            if(s[nr]){
                if(nnn[p[nr]]==0){
                    ans++;
                    ccc[p[nr]] += now[p[nr]];
                    cnt += ccc[p[nr]];
                }
                nnn[p[nr]]++;
                now[p[nr]]++;
                nr++;
            }else{
                now[p[nr]]++;
                nr++;
            }
        }
        while(nl<l[ni]){
            if(s[nl]){
                nnn[p[nl]]--;
                now[p[nl]]--;
                if(nnn[p[nl]]){
                    int ni = cnc[nl];
                    cnt += ccc[p[nl]] += ni;
                }else{
                    ans--;
                }
                nl++;
            }else{
                now[p[nl]]--;
                if(nnn[p[nl]]){
                    ccc[p[nl]]--;
                    cnt--;
                }
                nl++;
            }
        }
        while(nr>r[ni]){
            nr--;
            if(s[nr]){
            now[p[nr]]--;
                nnn[p[nr]]--;
                if(nnn[p[nr]]==0){
                    cnt -= ccc[p[nr]];
                    ccc[p[nr]] = 0;
                    ans--;
                }
            }else{
                now[p[nr]]--;
            }
        }
        aa[ni] = make_pair(ans,cnt);
    }
    for(int i = 0;i<q;i++) cout<<aa[i].first<<" "<<aa[i].second<<endl;
}
0