結果

問題 No.2338 Range AtCoder Query
ユーザー RubikunRubikun
提出日時 2023-06-02 22:29:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,453 ms / 4,000 ms
コード長 3,604 bytes
コンパイル時間 2,721 ms
コンパイル使用メモリ 223,388 KB
実行使用メモリ 278,396 KB
最終ジャッジ日時 2023-08-28 04:30:36
合計ジャッジ時間 59,254 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 217 ms
272,220 KB
testcase_01 AC 216 ms
272,372 KB
testcase_02 AC 217 ms
272,224 KB
testcase_03 AC 215 ms
272,180 KB
testcase_04 AC 215 ms
272,108 KB
testcase_05 AC 215 ms
272,132 KB
testcase_06 AC 219 ms
272,156 KB
testcase_07 AC 219 ms
272,196 KB
testcase_08 AC 215 ms
272,184 KB
testcase_09 AC 215 ms
272,180 KB
testcase_10 AC 216 ms
272,148 KB
testcase_11 AC 1,813 ms
276,464 KB
testcase_12 AC 1,872 ms
276,484 KB
testcase_13 AC 1,854 ms
276,524 KB
testcase_14 AC 2,146 ms
275,944 KB
testcase_15 AC 2,274 ms
277,216 KB
testcase_16 AC 2,834 ms
278,300 KB
testcase_17 AC 2,837 ms
278,316 KB
testcase_18 AC 2,858 ms
278,312 KB
testcase_19 AC 2,885 ms
278,396 KB
testcase_20 AC 2,952 ms
278,296 KB
testcase_21 AC 3,257 ms
278,336 KB
testcase_22 AC 3,453 ms
278,300 KB
testcase_23 AC 3,132 ms
278,308 KB
testcase_24 AC 3,179 ms
278,388 KB
testcase_25 AC 2,963 ms
278,372 KB
testcase_26 AC 285 ms
273,488 KB
testcase_27 AC 255 ms
273,488 KB
testcase_28 AC 261 ms
273,496 KB
testcase_29 AC 2,988 ms
278,304 KB
testcase_30 AC 2,444 ms
278,336 KB
testcase_31 AC 1,212 ms
278,300 KB
testcase_32 AC 1,130 ms
278,328 KB
testcase_33 AC 408 ms
278,304 KB
testcase_34 AC 408 ms
278,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

deque<int> AC[MAX],WA[MAX];

const int D=700;

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;
    }
    
    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(si(AC[x])==0){
                    wa+=si(WA[x]);
                    ac++;
                }
                AC[x].push_back(r);
            }else{
                int x=~A[r];
                WA[x].push_back(r);
            }
        }
        
        while(S[i].l<l){
            l--;
            if(A[l]>=0){
                int x=A[l];
                if(si(AC[x])>=1){
                    int ne=AC[x][0];
                    wa-=lower_bound(all(WA[x]),ne)-WA[x].begin();
                }else{
                    ac++;
                }
                AC[x].push_front(l);
            }else{
                int x=~A[l];
                if(si(AC[x])>=1){
                    wa++;
                }
                WA[x].push_front(l);
            }
        }
        while(S[i].r<r){
            if(A[r]>=0){
                int x=A[r];
                if(si(AC[x])==1){
                    wa-=si(WA[x]);
                    ac--;
                }
                AC[x].pop_back();
            }else{
                int x=~A[r];
                WA[x].pop_back();
            }
            r--;
        }
        while(S[i].l>l){
            if(l>=0){
                if(A[l]>=0){
                    int x=A[l];
                    if(si(AC[x])==1){
                        ac--;
                    }else{
                        int ne=AC[x][1];
                        wa+=lower_bound(all(WA[x]),ne)-WA[x].begin();
                    }
                    AC[x].pop_front();
                }else{
                    int x=~A[l];
                    if(si(AC[x])>=1){
                        wa--;
                    }
                    WA[x].pop_front();
                }
            }
            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