結果

問題 No.2338 Range AtCoder Query
ユーザー momoyuumomoyuu
提出日時 2023-06-02 23:59:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,448 bytes
コンパイル時間 4,659 ms
コンパイル使用メモリ 280,748 KB
実行使用メモリ 27,764 KB
最終ジャッジ日時 2023-08-28 06:42:16
合計ジャッジ時間 11,724 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,076 KB
testcase_01 AC 6 ms
10,332 KB
testcase_02 AC 5 ms
10,148 KB
testcase_03 AC 6 ms
10,128 KB
testcase_04 AC 6 ms
10,040 KB
testcase_05 AC 6 ms
10,052 KB
testcase_06 AC 10 ms
10,092 KB
testcase_07 AC 11 ms
10,120 KB
testcase_08 AC 10 ms
10,084 KB
testcase_09 AC 11 ms
10,076 KB
testcase_10 AC 10 ms
10,040 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

int main(){
    int n,m,q;
    cin>>n>>m>>q;
    vector<int> p(n);
    vector<string> s(n);
    for(int i = 0;i<n;i++){
        cin>>p[i]>>s[i];
    }
    int mx = 2e5;
    const int B = 700;
    vector<int> nnn(mx+1,0);
    vector<int> now(mx+1,0);
    vector<int> l(q),r(q);
    vector<int> ccc(mx+1,0);
    vector<int> cnc(n,0);
    vector<int> nxt(n,-1);
    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]]=="AC"){
                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]/n) 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]=="AC"){
        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]=="AC"){
                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]=="AC"){
                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]=="AC"){
                nnn[p[nl]]--;
                now[p[nl]]--;
                if(nnn[p[nl]]){
                    //int ii = nnn[p[nl]][0];
                    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]=="AC"){
            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