結果

問題 No.2338 Range AtCoder Query
ユーザー momoyuumomoyuu
提出日時 2023-06-03 00:20:57
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,210 bytes
コンパイル時間 5,365 ms
コンパイル使用メモリ 271,300 KB
実行使用メモリ 169,544 KB
最終ジャッジ日時 2023-08-28 06:59:42
合計ジャッジ時間 14,565 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
147,780 KB
testcase_01 AC 120 ms
147,556 KB
testcase_02 AC 119 ms
147,620 KB
testcase_03 AC 119 ms
147,420 KB
testcase_04 AC 118 ms
147,528 KB
testcase_05 AC 117 ms
147,492 KB
testcase_06 AC 126 ms
147,484 KB
testcase_07 AC 124 ms
147,552 KB
testcase_08 AC 126 ms
147,488 KB
testcase_09 AC 126 ms
147,560 KB
testcase_10 AC 125 ms
147,624 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 #

#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 = 600;
    vector<set<int>> nnn(mx+1);
    vector<deque<int>> now(mx+1);
    vector<int> l(q),r(q);
    vector<int> ccc(mx+1,0);
    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]=="AC"){
        ans++;
        nnn[p[0]].insert(0);
        now[p[0]].push_front(0);
    }else{
        now[p[0]].push_back(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]].insert(nl);
                if(nnn[p[nl]].size()==1) ans++;
                now[p[nl]].push_front(nl);
            }else{
                if(nnn[p[nl]].size()){
                    cnt++;
                    ccc[p[nl]]++;
                }
                now[p[nl]].push_front(nl);
            }
        }
        while(nr<r[ni]){
            if(s[nr]=="AC"){
                if(nnn[p[nr]].size()==0){
                    ans++;
                    ccc[p[nr]] += now[p[nr]].size();
                    cnt += ccc[p[nr]];
                }
                nnn[p[nr]].insert(nr);
                now[p[nr]].push_back(nr);
                nr++;
            }else{
                now[p[nr]].push_back(nr);
                nr++;
            }
        }
        while(nl<l[ni]){
            if(s[nl]=="AC"){
                nnn[p[nl]].erase(nl);
                now[p[nl]].pop_front();
                if(nnn[p[nl]].size()){
                    int ii = *nnn[p[nl]].begin();
                    int ni = lower_bound(now[p[nl]].begin(),now[p[nl]].end(),ii) - now[p[nl]].begin();
                    cnt += ccc[p[nl]] += ni;
                }else{
                    ans--;
                }
                nl++;
            }else{
                now[p[nl]].pop_front();
                if(nnn[p[nl]].size()){
                    ccc[p[nl]]--;
                    cnt--;
                }
                nl++;
            }
        }
        while(nr>r[ni]){
            nr--;
            if(s[nr]=="AC"){
                now[p[nr]].pop_back();
                nnn[p[nr]].erase(nr);
                if(nnn[p[nr]].size()==0){
                    cnt -= ccc[p[nr]];
                    ccc[p[nr]] = 0;
                    ans--;
                }
            }else{
                now[p[nr]].pop_back();
            }
        }
        aa[ni] = make_pair(ans,cnt);
        //cout<<i<<" "<<nl<<" "<<nr<<" "<<ans<<" "<<cnt<<endl;
        //cout<<nnn[2].size()<<endl;
    }

    for(int i = 0;i<q;i++) cout<<aa[i].first<<" "<<aa[i].second<<endl;

}
0