結果
問題 | No.259 セグメントフィッシング+ |
ユーザー | 👑 Nachia |
提出日時 | 2020-10-24 17:38:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 143 ms / 2,000 ms |
コード長 | 2,657 bytes |
コンパイル時間 | 2,682 ms |
コンパイル使用メモリ | 176,996 KB |
実行使用メモリ | 14,256 KB |
最終ジャッジ日時 | 2023-09-28 20:31:49 |
合計ジャッジ時間 | 8,290 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,384 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 130 ms
14,108 KB |
testcase_09 | AC | 130 ms
14,252 KB |
testcase_10 | AC | 131 ms
14,100 KB |
testcase_11 | AC | 131 ms
14,112 KB |
testcase_12 | AC | 130 ms
13,924 KB |
testcase_13 | AC | 140 ms
13,952 KB |
testcase_14 | AC | 140 ms
14,028 KB |
testcase_15 | AC | 142 ms
14,120 KB |
testcase_16 | AC | 142 ms
14,072 KB |
testcase_17 | AC | 141 ms
14,072 KB |
testcase_18 | AC | 142 ms
13,924 KB |
testcase_19 | AC | 141 ms
14,084 KB |
testcase_20 | AC | 142 ms
14,028 KB |
testcase_21 | AC | 143 ms
14,256 KB |
testcase_22 | AC | 142 ms
13,920 KB |
testcase_23 | AC | 80 ms
6,424 KB |
testcase_24 | AC | 104 ms
13,880 KB |
testcase_25 | AC | 104 ms
14,088 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) template< class S, S(*op)(S a, S b), S(*e)() > struct segtree { private: int N; vector<S> V; public: segtree(int n) { N = 1; while (N < n) N *= 2; V.assign(N * 2, e()); } segtree(vector<S> A) { N = 1; while (N < A.size()) N *= 2; V.assign(N * 2, e()); rep(i, A.size()) V[N + i] = A[i]; for (int i = N - 1; i >= 1; i--) V[i] = op(V[i * 2], V[i * 2 + 1]); } void set(int p, S v) { p += N; V[p] = v; while (p != 1) { p /= 2; V[p] = op(V[p * 2], V[p * 2 + 1]); } } S get(int p) { p += N; return V[p]; } S prod(int l, int r) { S ans_l = e(), ans_r = e(); l += N; r += N; while (l < r) { if (l & 1) ans_l = op(ans_l, V[l++]); if (r & 1) ans_r = op(V[--r], ans_r); l /= 2; r /= 2; } return op(ans_l, ans_r); } }; struct S { LL x; }; S op(S l, S r) { return { l.x + r.x }; } S e() { return { 0 }; } using RQ = segtree<S, op, e>; struct Query { char c; int t, y, z; int i; bool operator<(Query r) const { return t < r.t; } }; int main() { int N, Q; cin >> N >> Q; RQ G(N * 2); auto applyT = [N](int p, int t)->int { return (p + t) % (2 * N); }; vector<Query> queries; vector<LL> ans; { int q = 0; rep(i, Q) { char c; int t, y, z; cin >> c >> t >> y >> z; queries.push_back({ c,t,y,z,q }); if (c == 'C') q++; } ans.resize(q); } sort(queries.begin(), queries.end()); for (auto q : queries) { char c = q.c; int y = q.y, z = q.z, t = q.t; int i = q.i; if (c == 'L') { y = applyT(y, t); G.set(y, op(G.get(y), S{ z })); } if (c == 'R') { y = applyT(N * 2 - 1 - y, t); G.set(y, op(G.get(y), S{ z })); } if (c == 'C') { LL tmp = 0; int xl = applyT(y, t); int xr = applyT(z, t); if (xl < xr) tmp += G.prod(xl, xr).x; else tmp += G.prod(0, xr).x + G.prod(xl, 2 * N).x; xl = applyT(2 * N - z, t); xr = applyT(2 * N - y, t); if (xl < xr) tmp += G.prod(xl, xr).x; else tmp += G.prod(0, xr).x + G.prod(xl, 2 * N).x; ans[i] = tmp; } } for (LL a : ans) cout << a << endl; return 0; }