結果
| 問題 |
No.2338 Range AtCoder Query
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2023-06-02 23:45:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,357 bytes |
| コンパイル時間 | 2,391 ms |
| コンパイル使用メモリ | 211,900 KB |
| 最終ジャッジ日時 | 2025-02-13 21:27:40 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 WA * 2 RE * 3 TLE * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct t3{int left, right, index;};
bool sec_sort(t3 a, t3 b){return a.right < b.right;}
int main(){
int n, m, q;
cin >> n >> m >> q;
vector<int> prob(n);
vector<int> dat(n);
vector<int> lftwa(m);
vector<int> nowcnt(m);
for (int i=0; i<n; i++){
int p; string s; cin >> p >> s;
p--;
prob[i] = p;
if (s == "AC"){
dat[i] = 1;
lftwa[i] = nowcnt[p];
}else{
dat[i] = 0;
nowcnt[p]++;
}
}
int sep = ceil(sqrt(n));
vector<vector<t3>> mo(sep+1, vector<t3>(0));
t3 f;
for(int i=0; i<q; i++){
int l, r;
cin >> l >> r;
l--;
f.left = l;
f.right = r;
f.index = i;
mo[l/sep].push_back(f);
}
vector<int> ans1(q); // AC
vector<int> ans2(q); // WA
vector<deque<int>> ac;
ac.resize(m);
vector<int> lftsum(m);
int l = 0, r = 0;
int tl, tr;
int nowans1 = 0;
int nowans2 = 0;
for(int i=0; i<sep+1; i++){
sort(mo[i].begin(), mo[i].end(), sec_sort);
for(int j=0; j<mo[i].size(); j++){
tl = mo[i][j].left;
tr = mo[i][j].right;
//右を伸ばす
for(int k=r; k<tr; k++){
if (dat[k] == 1){
if (ac[prob[k]].empty()){
nowans1++;
nowans2 += lftwa[k] - lftsum[prob[k]];
}
ac[prob[k]].push_back(k);
}
}
//右を縮ませる
for(int k=r-1; k>=tr; k--){
if (dat[k] == 1){
if ((int)ac[prob[k]].size() == 1){
nowans2 -= lftwa[k] - lftsum[prob[k]];
}
ac[prob[k]].pop_back();
if (ac[prob[k]].empty()){
nowans1--;
}
}
}
//左を縮ませる
for(int k=l; k<tl; k++){
if (dat[k] == 1){
ac[prob[k]].pop_front();
if (!ac[prob[k]].empty()){
nowans2 += lftwa[ac[prob[k]].front()] - lftsum[prob[k]];
}else{
nowans1--;
}
}else{
lftsum[prob[k]]++;
if (!ac[prob[k]].empty()) nowans2--;
}
}
//左を伸ばす
for(int k=l-1; k>=tl; k--){
if (dat[k] == 1){
if (!ac[prob[k]].empty()){
nowans2 -= lftwa[ac[prob[k]].front()] - lftsum[prob[k]];
}else{
nowans1++;
}
ac[prob[k]].push_front(k);
}else{
lftsum[prob[k]]--;
if (!ac[prob[k]].empty()) nowans2++;
}
}
l = tl; r = tr;
ans1[mo[i][j].index] = nowans1;
ans2[mo[i][j].index] = nowans2;
}
}
for(int i=0; i<q; i++){
cout << ans1[i] << " " << ans2[i] << "\n";
}
}
shobonvip