結果
| 問題 |
No.2338 Range AtCoder Query
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2023-05-30 17:22:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 206 ms / 4,000 ms |
| コード長 | 1,899 bytes |
| コンパイル時間 | 1,261 ms |
| コンパイル使用メモリ | 103,400 KB |
| 最終ジャッジ日時 | 2025-02-13 16:35:35 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 34 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#include <atcoder/segtree>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;
i64 addst(i64 a, i64 b){ return a + b; }
i64 est(){ return 0; }
int main(){
int N, M, Q; cin >> N >> M >> Q;
vector<int> P(N);
vector<int> isac(N);
rep(i,N){
cin >> P[i]; P[i]--;
string s; cin >> s;
isac[i] = (s[0] == 'A' ? 1 : 0);
}
vector<int> head(M, -1);
atcoder::segtree<i64, addst, est> rqA(N);
atcoder::segtree<i64, addst, est> rqW(N);
struct Query { int l, r, i; };
vector<Query> queries;
rep(i,Q){
int l,r; cin >> l >> r; l--;
queries.push_back({l,r,i});
}
vector<int> ansA(Q), ansW(Q);
sort(queries.begin(), queries.end(), [](Query a, Query b){ return a.l > b.l; });
int nowL = N;
for(auto q : queries){
while(q.l < nowL){
int p = --nowL;
int m = P[p];
if(isac[p]){
if(head[m] >= 0){
rqA.set(head[m], 0);
rqW.set(head[m], 0);
}
head[m] = p;
rqA.set(head[m], 1);
}
else{
if(head[m] >= 0){
rqW.set(head[m], rqW.get(head[m]) + 1);
}
}
}
ansA[q.i] = rqA.prod(q.l, q.r);
ansW[q.i] = rqW.prod(q.l, q.r);
}
rep(i,Q){
cout << ansA[i] << ' ' << ansW[i] << '\n';
}
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia