結果
問題 | No.2421 entersys? |
ユーザー | ayataka5 |
提出日時 | 2023-08-12 14:58:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,312 bytes |
コンパイル時間 | 5,127 ms |
コンパイル使用メモリ | 234,752 KB |
実行使用メモリ | 41,812 KB |
最終ジャッジ日時 | 2024-11-19 22:26:56 |
合計ジャッジ時間 | 29,376 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; struct LazySegmentTree { private: int n; vector<ll> node, lazy; public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1); lazy.resize(2*n-1, 0); for(int i=0; i<sz; i++) node[i+n-1] = v[i]; for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2]; } void eval(int k, int l, int r) { if(lazy[k] != 0) { node[k] += lazy[k]; if(r - l > 1) { lazy[2*k+1] += lazy[k] / 2; lazy[2*k+2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2*k+1, l, (l+r)/2); add(a, b, x, 2*k+2, (l+r)/2, r); node[k] = node[2*k+1] + node[2*k+2]; } } ll getsum(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return 0; if(a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2*k+1, l, (l+r)/2); ll vr = getsum(a, b, 2*k+2, (l+r)/2, r); return vl + vr; } }; int main() { int N; cin >> N; vector X(N, ""s); vector L(N, 0), R(N, 0); for(int i = 0; i < N; i++) { cin >> X[i] >> L[i] >> R[i]; } int Q; cin >> Q; vector q(Q, 0), t1(0, 0), t2(0, 0), l3(0, 0), r3(0, 0); vector x1(0, ""s), x3(0, ""s); for(int i = 0; i < Q; i++) { cin >> q[i]; if(q[i] == 1) { string x; int t; cin >> x >> t; x1.push_back(x); t1.push_back(t); } if(q[i] == 2) { int t; cin >> t; t2.push_back(t); } if(q[i] == 3) { string x; int l, r; cin >> x >> l >> r; x3.push_back(x); l3.push_back(l); r3.push_back(r); } } vector P(0, 0); for(int i = 0; i < N; i++) { P.push_back(L[i]); P.push_back(R[i]); } for(int i = 0; i < t1.size(); i++) { P.push_back(t1[i]); } for(int i = 0; i < t2.size(); i++) { P.push_back(t2[i]); } for(int i = 0; i < l3.size(); i++) { P.push_back(l3[i]); P.push_back(r3[i]); } vector PP(P); sort(begin(PP), end(PP)); PP.erase(unique(begin(PP), end(PP)), end(PP)); int NN(PP.size()); for(int i = 0; i < P.size(); i++) { P[i] = lower_bound(begin(PP), end(PP), P[i]) - begin(PP); } for(int i = 0; i < N; i++) { L[i] = P[i*2]; R[i] = P[i*2+1]; } for(int i = 0; i < t1.size(); i++) { t1[i] = P[N*2 + i]; } for(int i = 0; i < t2.size(); i++) { t2[i] = P[N*2 + t1.size() + i]; } for(int i = 0; i < l3.size(); i++) { l3[i] = P[N*2 + t1.size() + t2.size() + i*2]; r3[i] = P[N*2 + t1.size() + t2.size() + i*2+1]; } map<string, vector<pair<int, int>>> mp; for(int i = 0; i < N; i++) { mp[X[i]].push_back({L[i], R[i]}); } LazySegmentTree seg( vector<ll>(NN, 0) ); for(int i = 0; i < N; i++) { seg.add(L[i], R[i]+1, 1); } for(int i = 0; i < NN; i++) { if(i != 0) cout << ' '; cout << seg.getsum(i, i+1); } cout << endl; int idx1(0), idx2(0), idx3(0); for(int i = 0; i < Q; i++) { if(q[i] == 1) { string ans("No"); vector V(mp[x1[idx1]]); for(auto [x, y] : V) { if(x <= t1[idx1] && t1[idx1] <= y) { ans = "Yes"; } } cout << ans << endl; idx1++; } if(q[i] == 2) { cout << seg.getsum(t2[idx2], t2[idx2]+1) << endl; idx2++; } if(q[i] == 3) { seg.add(l3[idx3], r3[idx3]+1, 1); mp[x3[idx3]].push_back({l3[idx3], r3[idx3]}); idx3++; } } return 0; }