結果

問題 No.2338 Range AtCoder Query
ユーザー FplusFplusFFplusFplusF
提出日時 2023-06-02 23:23:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,675 bytes
コンパイル時間 4,660 ms
コンパイル使用メモリ 251,880 KB
実行使用メモリ 48,312 KB
最終ジャッジ日時 2023-08-28 05:56:31
合計ジャッジ時間 11,713 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,380 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;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
struct Mo{
    int n;
    vector<pair<int,int>> lr;
    Mo(int x){
        n=x;
    }
    void add(int l,int r){
        lr.emplace_back(l,r);
    }
    template<class IL,class IR,class EL,class ER,class O> void solve(IL &insert_left,IR &insert_right,EL &erase_left,ER &erase_right,O &output){
        int q=lr.size();
        if(q==0) return;
        int block_size=max(1,n/(int)sqrt(q));
        vector<int> ord(q);
        for(int i=0;i<q;i++) ord[i]=i;
        sort(ord.begin(),ord.end(),
        [&](int i,int j){
            int block_i=lr[i].first/block_size,block_j=lr[j].first/block_size;
            if(block_i!=block_j) return lr[i].first<lr[j].first;
            if(block_i&1) return lr[i].second>lr[j].second;
            else return lr[i].second<lr[j].second;
        }
        );
        int l=0,r=0;
        for(auto &idx:ord){
            while(lr[idx].first<l) l--,insert_left(l);
            while(r<lr[idx].second) insert_right(r),r++;
            while(l<lr[idx].first) erase_left(l),l++;
            while(lr[idx].second<r) r--,erase_right(r);
            output(idx);
        }
    }
    template<class I,class E,class O> void solve(I &insert,E &erase,O &output){
        solve(insert,insert,erase,erase,output);
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m,q;
    cin >> n >> m >> q;
    vector<ll> p(n);
    vector<bool> s(n);
    rep(i,n){
        cin >> p[i];
        p[i]--;
        string str;
        cin >> str;
        if(str=="AC") s[i]=true;
        if(str=="WA") s[i]=false;
    }
    Mo mo(n);
    vector<ll> ac(q),wa(q);
    rep(i,q){
        ll l,r;
        cin >> l >> r;
        l--;
        mo.add(l,r);
    }
    vector<tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>> a(m),w(m);
    ll now_a=0,now_w=0;
    auto il=[&](ll i){
        if(s[i]){
            if((ll)a[p[i]].size()==0) now_a++;
            else now_w-=w[p[i]].order_of_key(*begin(a[p[i]]));
            a[p[i]].insert(i);
        }else{
            if(1<=(ll)a[p[i]].size()) now_w++;
            w[p[i]].insert(i);
        }
    };
    auto ir=[&](ll i){
        if(s[i]){
            if((ll)a[p[i]].size()==0){
                now_a++;
                now_w+=w[p[i]].order_of_key(i);
            }
            a[p[i]].insert(i);
        }else{ 
            w[p[i]].insert(i);
        }
    };
    auto el=[&](ll i){
        if(s[i]){
            a[p[i]].erase(i);
            if((ll)a[p[i]].size()==0){
                now_a--;
            }else{
                now_w-=w[p[i]].order_of_key(i);
                now_w+=w[p[i]].order_of_key(*begin(a[p[i]]));
            }
        }else{
            w[p[i]].erase(i);
            if(1<=(ll)a[p[i]].size()) now_w--;
        }
    };
    auto er=[&](ll i){
        if(s[i]){
            a[p[i]].erase(i);
            if((ll)a[p[i]].size()==0){
                now_a--;
                now_w-=w[p[i]].order_of_key(i);
            }
        }else{
            w[p[i]].erase(i);
        }
    };
    auto o=[&](ll i){
        ac[i]=now_a;
        wa[i]=now_w;
    };
    mo.solve(il,ir,el,er,o);
    rep(i,q){
        cout << ac[i] << " " << wa[i] << '\n';
    }
}
0