結果
問題 | No.2338 Range AtCoder Query |
ユーザー | milanis48663220 |
提出日時 | 2023-06-02 23:03:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,554 bytes |
コンパイル時間 | 2,060 ms |
コンパイル使用メモリ | 151,172 KB |
実行使用メモリ | 146,392 KB |
最終ジャッジ日時 | 2024-06-09 01:08:01 |
合計ジャッジ時間 | 54,124 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 114 ms
137,716 KB |
testcase_01 | AC | 115 ms
137,876 KB |
testcase_02 | AC | 116 ms
137,856 KB |
testcase_03 | AC | 115 ms
137,856 KB |
testcase_04 | AC | 116 ms
137,984 KB |
testcase_05 | AC | 113 ms
137,856 KB |
testcase_06 | AC | 116 ms
137,856 KB |
testcase_07 | AC | 119 ms
137,900 KB |
testcase_08 | AC | 115 ms
137,852 KB |
testcase_09 | AC | 116 ms
137,856 KB |
testcase_10 | AC | 118 ms
137,728 KB |
testcase_11 | AC | 2,741 ms
142,724 KB |
testcase_12 | AC | 2,815 ms
142,432 KB |
testcase_13 | AC | 3,105 ms
142,996 KB |
testcase_14 | AC | 2,825 ms
142,660 KB |
testcase_15 | AC | 3,799 ms
143,940 KB |
testcase_16 | AC | 3,959 ms
144,984 KB |
testcase_17 | TLE | - |
testcase_18 | AC | 3,996 ms
145,108 KB |
testcase_19 | AC | 3,699 ms
144,984 KB |
testcase_20 | AC | 3,995 ms
145,240 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 3,930 ms
145,116 KB |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | AC | 192 ms
138,592 KB |
testcase_27 | AC | 157 ms
138,384 KB |
testcase_28 | AC | 164 ms
138,368 KB |
testcase_29 | AC | 3,736 ms
146,268 KB |
testcase_30 | AC | 3,589 ms
146,392 KB |
testcase_31 | AC | 1,423 ms
144,088 KB |
testcase_32 | AC | 1,408 ms
144,088 KB |
testcase_33 | AC | 279 ms
143,960 KB |
testcase_34 | AC | 265 ms
144,216 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <random> std::random_device rnd; std::mt19937 mt(rnd()); std::mt19937_64 mt_ll(rnd()); int randint(const int l, const int r){ return mt()%(r - l) + l; } long long randll(const long long l, const long long r){ return mt_ll()%(r - l) + l; } #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } int maxn; ll hilbertorder(int x, int y) { ll rx, ry, d = 0; for (ll s=maxn>>1; s; s>>=1) { rx = (x & s)>0, ry = (y & s)>0; d += s * s * ((rx * 3) ^ ry); if (ry) continue; if (rx) { x = maxn-1 - x; y = maxn-1 - y; } swap(x, y); } return d; } template<typename T> class Mo{ public: vector<int> l, r; int bucket_size; Mo(int bucket_size): l(vector<int>()), r(vector<int>()), bucket_size(bucket_size) {} void add_query(int l_, int r_){ l.push_back(l_); r.push_back(r_); } template<typename ADD_L, typename ADD_R, typename DEL_L, typename DEL_R, typename GET_ANS> vector<T> solve(ADD_L add_left, ADD_R add_right, DEL_L del_left, DEL_R del_right, GET_ANS get_ans){ int sz = l.size(); vector<int> ord(sz); int q = l.size(); vector<ll> eval(q); for(int i = 0; i < q; i++) eval[i] = hilbertorder(l[i], r[i]); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](const int a, const int b){ return eval[a] < eval[b]; }); int li = 0, ri = 0; vector<T> ans(sz); for(const int i : ord){ while(li > l[i]) add_left(--li); while(ri < r[i]) add_right(ri++); while(li < l[i]) del_left(li++); while(ri > r[i]) del_right(--ri); ans[i] = get_ans(); } return ans; } }; const int N = 200000; using P = pair<bool, int>; deque<P> dq[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m, q; cin >> n >> m >> q; maxn = 1; while(maxn < n ) maxn <<= 1; vector<int> p(n); vector<bool> s(n); for(int i = 0; i < n; i++){ int pp; cin >> pp; pp--; string ss; cin >> ss; p[i] = pp; s[i] = ss == "AC"; } int ac = 0, penalty = 0; auto get_current_ac = [&](int idx){ if(dq[idx].empty()) return 0; if(dq[idx].size() >= 2) return 1; return dq[idx][0].first ? 1 : 0; }; auto get_current_penalty = [&](int idx){ if(get_current_ac(idx) == 0) return 0; if(dq[idx].empty()) return 0; if(dq[idx][0].first) return 0; return dq[idx][0].second; }; auto subtract_current = [&](int idx){ ac -= get_current_ac(idx); penalty -= get_current_penalty(idx); }; auto add_current = [&](int idx){ ac += get_current_ac(idx); penalty += get_current_penalty(idx); }; auto add_left = [&](int i){ subtract_current(p[i]); if(dq[p[i]].empty()){ dq[p[i]].push_front({s[i], 1}); }else{ auto [f, cnt] = dq[p[i]].front(); if(f == s[i]){ dq[p[i]].front().second++; }else{ dq[p[i]].push_front({s[i], 1}); } } add_current(p[i]); }; auto add_right = [&](int i){ subtract_current(p[i]); if(dq[p[i]].empty()){ dq[p[i]].push_back({s[i], 1}); }else{ auto [f, cnt] = dq[p[i]].back(); if(f == s[i]){ dq[p[i]].back().second++; }else{ dq[p[i]].push_back({s[i], 1}); } } add_current(p[i]); }; auto del_left = [&](int i){ subtract_current(p[i]); dq[p[i]].front().second--; if(dq[p[i]].front().second == 0) dq[p[i]].pop_front(); add_current(p[i]); }; auto del_right = [&](int i){ subtract_current(p[i]); dq[p[i]].back().second--; if(dq[p[i]].back().second == 0) dq[p[i]].pop_back(); add_current(p[i]); }; auto get_ans = [&](){ return make_pair(ac, penalty); }; int sq = sqrt(n); auto mo = Mo<pair<int, int>>(sq); for(int i = 0; i < q; i++){ int l, r; cin >> l >> r; l--; mo.add_query(l, r); } auto ans = mo.solve(add_left, add_right, del_left, del_right, get_ans); for(auto [a, p]: ans){ cout << a << ' ' << p << '\n'; } }