結果

問題 No.2338 Range AtCoder Query
ユーザー RubikunRubikun
提出日時 2023-06-03 00:21:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 696 ms / 4,000 ms
コード長 3,797 bytes
コンパイル時間 3,903 ms
コンパイル使用メモリ 237,876 KB
実行使用メモリ 22,864 KB
最終ジャッジ日時 2023-08-28 07:00:34
合計ジャッジ時間 19,163 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,464 KB
testcase_01 AC 5 ms
9,588 KB
testcase_02 AC 5 ms
9,724 KB
testcase_03 AC 4 ms
9,748 KB
testcase_04 AC 4 ms
9,520 KB
testcase_05 AC 5 ms
9,480 KB
testcase_06 AC 6 ms
9,576 KB
testcase_07 AC 6 ms
9,552 KB
testcase_08 AC 6 ms
9,544 KB
testcase_09 AC 6 ms
9,528 KB
testcase_10 AC 6 ms
9,588 KB
testcase_11 AC 543 ms
17,228 KB
testcase_12 AC 511 ms
17,320 KB
testcase_13 AC 563 ms
17,444 KB
testcase_14 AC 529 ms
17,028 KB
testcase_15 AC 644 ms
18,308 KB
testcase_16 AC 692 ms
20,564 KB
testcase_17 AC 696 ms
20,580 KB
testcase_18 AC 693 ms
20,620 KB
testcase_19 AC 689 ms
20,544 KB
testcase_20 AC 692 ms
20,552 KB
testcase_21 AC 694 ms
20,540 KB
testcase_22 AC 685 ms
20,608 KB
testcase_23 AC 695 ms
20,584 KB
testcase_24 AC 690 ms
20,556 KB
testcase_25 AC 690 ms
20,588 KB
testcase_26 AC 72 ms
15,724 KB
testcase_27 AC 67 ms
15,708 KB
testcase_28 AC 74 ms
15,764 KB
testcase_29 AC 322 ms
20,600 KB
testcase_30 AC 561 ms
20,576 KB
testcase_31 AC 277 ms
22,864 KB
testcase_32 AC 259 ms
22,728 KB
testcase_33 AC 180 ms
20,540 KB
testcase_34 AC 175 ms
20,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=200005,INF=1<<30;

struct dat{
    int l;
    int r;
    int id;
};

int AC[MAX],WA[MAX];

const int D=700;

vector<int> mae[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M,Q;cin>>N>>M>>Q;
    
    vector<int> A(N);
    for(int i=0;i<N;i++){
        int x;cin>>x;x--;
        string S;cin>>S;
        if(S=="AC") A[i]=x;
        else A[i]=~x;
        mae[x].push_back(i);
    }
    
    vector<int> ato(N);
    
    for(int i=M-1;i>=0;i--){
        reverse(all(mae[i]));
        bool deta=false;
        int cn=0;
        for(int x:mae[i]){
            if(A[x]>=0){
                if(deta){
                    ato[x]=cn;
                }else{
                    deta=true;
                }
                cn=0;
            }else{
                cn++;
            }
        }
    }
    
    int l=-1,r=-1;
    
    vector<dat> S(Q);
    vector<pair<int,int>> ans(Q);
    for(int i=0;i<Q;i++){
        cin>>S[i].l>>S[i].r;
        S[i].l--;
        S[i].r--;
        S[i].id=i;
    }
    
    vector<int> usel;
    for(int i=0;i<Q;i++) usel.push_back(S[i].l/D);
    sort(all(usel));
    usel.erase(unique(all(usel)),usel.end());
    vector<int> ty(N);
    for(int i=0;i<si(usel);i++){
        ty[usel[i]]=i&1;
    }
    sort(all(S),[&](auto a,auto b){
        if(a.l/D==b.l/D){
            if(ty[a.l/D]) return a.r>b.r;
            else return a.r<b.r;
        }
        return a.l/D<b.l/D;
    });
    
    int ac=0,wa=0;
    
    for(int i=0;i<Q;i++){
        while(S[i].r>r){
            r++;
            if(A[r]>=0){
                int x=A[r];
                if(AC[x]==0){
                    wa+=WA[x];
                    ac++;
                }
                AC[x]++;
            }else{
                int x=~A[r];
                WA[x]++;
            }
        }
        
        while(S[i].l<l){
            l--;
            if(A[l]>=0){
                int x=A[l];
                if(AC[x]>=1){
                    wa-=ato[l];
                }else{
                    ac++;
                }
                AC[x]++;
            }else{
                int x=~A[l];
                if(AC[x]>=1){
                    wa++;
                }
                WA[x]++;
            }
        }
        while(S[i].r<r){
            if(A[r]>=0){
                int x=A[r];
                if(AC[x]==1){
                    wa-=WA[x];
                    ac--;
                }
                AC[x]--;
            }else{
                int x=~A[r];
                WA[x]--;
            }
            r--;
        }
        while(S[i].l>l){
            if(l>=0){
                if(A[l]>=0){
                    int x=A[l];
                    if(AC[x]==1){
                        ac--;
                    }else{
                        wa+=ato[l];
                    }
                    AC[x]--;
                }else{
                    int x=~A[l];
                    if(AC[x]>=1){
                        wa--;
                    }
                    WA[x]--;
                }
            }
            l++;
        }
        
        ans[S[i].id]=mp(ac,wa);
        
        //break;
    }
    
    for(int i=0;i<Q;i++) cout<<ans[i].fi<<" "<<ans[i].se<<"\n";
}
0