結果
問題 | No.2338 Range AtCoder Query |
ユーザー |
|
提出日時 | 2023-06-02 22:49:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 169 ms / 4,000 ms |
コード長 | 1,116 bytes |
コンパイル時間 | 1,708 ms |
コンパイル使用メモリ | 172,788 KB |
実行使用メモリ | 18,560 KB |
最終ジャッジ日時 | 2024-12-28 21:00:23 |
合計ジャッジ時間 | 8,969 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 34 |
ソースコード
#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); }