結果
問題 | No.2338 Range AtCoder Query |
ユーザー | no way |
提出日時 | 2023-06-02 22:49:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 161 ms / 4,000 ms |
コード長 | 1,116 bytes |
コンパイル時間 | 1,923 ms |
コンパイル使用メモリ | 169,520 KB |
実行使用メモリ | 18,524 KB |
最終ジャッジ日時 | 2023-08-28 05:03:56 |
合計ジャッジ時間 | 8,897 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
12,240 KB |
testcase_01 | AC | 4 ms
12,152 KB |
testcase_02 | AC | 4 ms
12,164 KB |
testcase_03 | AC | 4 ms
12,232 KB |
testcase_04 | AC | 4 ms
12,184 KB |
testcase_05 | AC | 4 ms
12,196 KB |
testcase_06 | AC | 4 ms
12,124 KB |
testcase_07 | AC | 4 ms
12,184 KB |
testcase_08 | AC | 4 ms
12,184 KB |
testcase_09 | AC | 5 ms
12,160 KB |
testcase_10 | AC | 5 ms
12,144 KB |
testcase_11 | AC | 110 ms
16,608 KB |
testcase_12 | AC | 108 ms
16,552 KB |
testcase_13 | AC | 115 ms
16,880 KB |
testcase_14 | AC | 100 ms
16,184 KB |
testcase_15 | AC | 131 ms
17,468 KB |
testcase_16 | AC | 155 ms
18,388 KB |
testcase_17 | AC | 154 ms
18,484 KB |
testcase_18 | AC | 152 ms
18,368 KB |
testcase_19 | AC | 154 ms
18,368 KB |
testcase_20 | AC | 157 ms
18,472 KB |
testcase_21 | AC | 155 ms
18,316 KB |
testcase_22 | AC | 157 ms
18,352 KB |
testcase_23 | AC | 158 ms
18,332 KB |
testcase_24 | AC | 158 ms
18,356 KB |
testcase_25 | AC | 155 ms
18,524 KB |
testcase_26 | AC | 39 ms
13,664 KB |
testcase_27 | AC | 39 ms
13,648 KB |
testcase_28 | AC | 40 ms
13,888 KB |
testcase_29 | AC | 149 ms
18,396 KB |
testcase_30 | AC | 161 ms
18,396 KB |
testcase_31 | AC | 150 ms
18,392 KB |
testcase_32 | AC | 142 ms
17,268 KB |
testcase_33 | AC | 107 ms
15,960 KB |
testcase_34 | AC | 108 ms
16,052 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; const int N=2e5+10; pair<int,int>ans[N],tree[N],f[N]; vector<pair<int,int>>w[N]; int n,m,q,x,y; int a[N],b[N]; char s[10]; void add(int x,pair<int,int>y){ while (x<=n){ tree[x].first+=y.first; tree[x].second+=y.second; x+=(x&(-x)); } } pair<int,int> solve(int x){ pair<int,int>ans=make_pair(0,0); while (x){ ans.first+=tree[x].first; ans.second+=tree[x].second; x-=(x&(-x)); } return ans; } int main(){ scanf("%d%d%d",&n,&m,&q); for (int i=1;i<=n;i++){ scanf("%d%s",&a[i],s); if (s[0]=='A') b[i]=1; else b[i]=0; } for (int i=1;i<=q;i++){ scanf("%d%d",&x,&y); w[x].push_back(make_pair(y,i)); } for (int i=n;i>=1;i--){ if (b[i]){ if (f[a[i]].first){ add(f[a[i]].first,make_pair(-1,-f[a[i]].second)); } f[a[i]].first=i; f[a[i]].second=0; add(i,make_pair(1,0)); }else{ if (f[a[i]].first){ add(f[a[i]].first,make_pair(0,1)); f[a[i]].second++; } } for (int j=0;j<w[i].size();j++){ ans[w[i][j].second]=solve(w[i][j].first); } } for (int i=1;i<=q;i++) printf("%d %d\n",ans[i].first,ans[i].second); }