結果
| 問題 |
No.2338 Range AtCoder Query
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2023-06-02 23:36:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,846 bytes |
| コンパイル時間 | 4,016 ms |
| コンパイル使用メモリ | 232,724 KB |
| 最終ジャッジ日時 | 2025-02-13 21:13:01 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 WA * 6 TLE * 17 MLE * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=int;
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);
}
};
ll f(deque<ll> &d,ll x){
ll n=d.size();
if(n==0) return 0;
if(x<d.front()) return 0;
if(d.back()<x) return n;
ll ok=0,ng=n-1;
while(1<abs(ok-ng)){
ll mid=(ok+ng)/2;
if(d[mid]<=x) ok=mid;
else ng=mid;
}
return ok;
}
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<deque<ll>> 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-=f(w[p[i]],a[p[i]].front());
a[p[i]].push_front(i);
}else{
if(1<=(ll)a[p[i]].size()) now_w++;
w[p[i]].push_front(i);
}
};
auto ir=[&](ll i){
if(s[i]){
if((ll)a[p[i]].size()==0){
now_a++;
now_w+=f(w[p[i]],i);
}
a[p[i]].push_back(i);
}else{
w[p[i]].push_back(i);
}
};
auto el=[&](ll i){
if(s[i]){
a[p[i]].pop_front();
if((ll)a[p[i]].size()==0){
now_a--;
}else{
now_w-=f(w[p[i]],i);
now_w+=f(w[p[i]],a[p[i]].front());
}
}else{
w[p[i]].pop_front();
if(1<=(ll)a[p[i]].size()) now_w--;
}
};
auto er=[&](ll i){
if(s[i]){
a[p[i]].pop_back();
if((ll)a[p[i]].size()==0){
now_a--;
now_w-=f(w[p[i]],i);
}
}else{
w[p[i]].pop_back();
}
};
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';
}
}
FplusFplusF