結果
問題 | No.259 セグメントフィッシング+ |
ユーザー | 👑 はまやんはまやん |
提出日時 | 2017-04-25 00:05:32 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 2,104 bytes |
コンパイル時間 | 1,846 ms |
コンパイル使用メモリ | 167,828 KB |
実行使用メモリ | 11,496 KB |
最終ジャッジ日時 | 2023-10-11 13:34:39 |
合計ジャッジ時間 | 5,466 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
11,216 KB |
testcase_01 | AC | 5 ms
11,224 KB |
testcase_02 | AC | 5 ms
11,348 KB |
testcase_03 | AC | 4 ms
11,272 KB |
testcase_04 | AC | 4 ms
11,288 KB |
testcase_05 | AC | 5 ms
11,260 KB |
testcase_06 | AC | 5 ms
11,256 KB |
testcase_07 | AC | 5 ms
11,212 KB |
testcase_08 | AC | 46 ms
11,296 KB |
testcase_09 | AC | 47 ms
11,340 KB |
testcase_10 | AC | 46 ms
11,260 KB |
testcase_11 | AC | 46 ms
11,236 KB |
testcase_12 | AC | 48 ms
11,204 KB |
testcase_13 | AC | 49 ms
11,340 KB |
testcase_14 | AC | 51 ms
11,344 KB |
testcase_15 | AC | 50 ms
11,208 KB |
testcase_16 | AC | 51 ms
11,304 KB |
testcase_17 | AC | 51 ms
11,216 KB |
testcase_18 | AC | 52 ms
11,496 KB |
testcase_19 | AC | 51 ms
11,356 KB |
testcase_20 | AC | 49 ms
11,356 KB |
testcase_21 | AC | 51 ms
11,236 KB |
testcase_22 | AC | 50 ms
11,444 KB |
testcase_23 | AC | 31 ms
11,360 KB |
testcase_24 | AC | 41 ms
11,288 KB |
testcase_25 | AC | 40 ms
11,284 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) typedef long long ll; #define def 0 template<class V, int NV> struct SegTree { V comp(V l, V r) { return l + r; }; vector<V> val; SegTree() { val = vector<V>(NV * 2, def); } V get(int l, int r) { //[l,r] if (l > r) return def; l += NV; r += NV + 1; V ret = def; while (l < r) { if (l & 1) ret = comp(ret, val[l++]); if (r & 1) ret = comp(ret, val[--r]); l /= 2; r /= 2; } return ret; } void update(int i, V v) { i += NV; val[i] = v; while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]); } void add(int i, V v) { update(i, val[i + NV] + v); } }; template<class V, int NV> struct ShiftSegTree { SegTree<V, NV> st; int NM, base; ShiftSegTree(int _NM) : NM(_NM), base(0) {} void shift(int x) { // 全ての要素をx分右へシフトする base -= x % NM; if (base < 0) base += NM; base %= NM; } V get(int l, int r) { //[l,r] l += base, r += base; if (NM <= l) return st.get(l % NM, r % NM); if (r < NM) return st.get(l, r); return st.comp(st.get(l, NM - 1), st.get(0, r % NM)); } void update(int i, V v) { st.update((i + base) % NM, v); } void add(int i, V v) { st.add((i + base) % NM, v); } void print() { rep(i, 0, NM) cout << get(i, i) << " "; cout << endl; } }; //----------------------------------------------------------------------------------- int main() { int N, Q; cin.tie(0); ios::sync_with_stdio(false); cin >> N >> Q; ShiftSegTree<ll, 1 << 19> sst(2 * N); int pt = 0; rep(q, 0, Q) { char x; int t, y, z; cin >> x >> t >> y >> z; sst.shift(t - pt); if (x == 'L') sst.add(2 * N - 1 - y, z); else if (x == 'R') sst.add(y, z); else { z--; ll right = sst.get(y, z); ll left = sst.get(2 * N - 1 - z, 2 * N - 1 - y); printf("%lld\n", right + left); } pt = t; } }