結果
問題 | No.1568 Sushi |
ユーザー | 👑 Nachia |
提出日時 | 2021-06-26 14:35:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 472 ms / 2,000 ms |
コード長 | 2,654 bytes |
コンパイル時間 | 1,136 ms |
コンパイル使用メモリ | 98,460 KB |
実行使用メモリ | 33,024 KB |
最終ジャッジ日時 | 2024-06-25 10:35:44 |
合計ジャッジ時間 | 14,496 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 9 ms
6,940 KB |
testcase_05 | AC | 7 ms
6,940 KB |
testcase_06 | AC | 8 ms
6,940 KB |
testcase_07 | AC | 7 ms
6,944 KB |
testcase_08 | AC | 9 ms
6,940 KB |
testcase_09 | AC | 414 ms
30,924 KB |
testcase_10 | AC | 369 ms
18,560 KB |
testcase_11 | AC | 370 ms
18,712 KB |
testcase_12 | AC | 362 ms
18,688 KB |
testcase_13 | AC | 416 ms
30,912 KB |
testcase_14 | AC | 366 ms
18,304 KB |
testcase_15 | AC | 440 ms
32,620 KB |
testcase_16 | AC | 378 ms
18,516 KB |
testcase_17 | AC | 472 ms
32,972 KB |
testcase_18 | AC | 442 ms
30,464 KB |
testcase_19 | AC | 432 ms
30,848 KB |
testcase_20 | AC | 368 ms
18,432 KB |
testcase_21 | AC | 422 ms
30,564 KB |
testcase_22 | AC | 421 ms
30,012 KB |
testcase_23 | AC | 452 ms
32,128 KB |
testcase_24 | AC | 409 ms
29,944 KB |
testcase_25 | AC | 436 ms
31,500 KB |
testcase_26 | AC | 447 ms
32,384 KB |
testcase_27 | AC | 461 ms
33,024 KB |
testcase_28 | AC | 400 ms
19,528 KB |
ソースコード
#include <iostream> #include <vector> #include <atcoder/segtree> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct RQS { ll minx, maxx, mindx, maxdx, dx; }; RQS RQop(RQS l, RQS r) { RQS res; res.minx = min(l.minx, l.dx + r.minx); res.maxx = max(l.maxx, l.dx + r.maxx); res.mindx = min(min(l.mindx,r.mindx), (r.minx + l.dx) - l.maxx); res.maxdx = max(max(l.maxdx,r.maxdx), (r.maxx + l.dx) - l.minx); res.dx = l.dx + r.dx; return res; } RQS RQe() { return { 0,0,0,0,0 }; } using RQ = atcoder::segtree<RQS, RQop, RQe>; RQS RQ_moveCCW(ll d){ return RQS{ -d,0,-d,0,-d }; } RQS RQ_moveCW(ll d){ return RQS{ 0,d,0,d,d }; } ll L,N,Q; vector<ll> A; vector<ll> dA; ll queryKey_D = 0; int ubound_A(ll t){ int l = 0, r = N+2; while(r-l > 1){ int m = (l+r) / 2; if(A[m-1] <= t) l = m; else r = m; } return l; } int main(){ cin >> L >> N >> Q; A.resize(N+1,0); rep(i,N) cin >> A[i+1]; RQ G(N); for(int i=0; i<N; i++){ if(i%2 == 0) G.set(i,RQ_moveCCW(A[i+1]-A[i])); else G.set(i,RQ_moveCW(A[i+1]-A[i])); } rep(i,N){ auto g = G.get(i); //cout << "(" << g.minx << ", " << g.maxx << ", " << g.mindx << ", " << g.maxdx << ", " << g.dx << ")" << endl; } rep(i,Q){ ll b,c; cin >> b >> c; b = (b+queryKey_D) % L; c = (c+queryKey_D) % 1'000'000'000'000'000; ll ans = -1; // cout << "b = "<< b << ", c = " << c << endl; int sp = ubound_A(c); // cout << "sp = " << sp << endl; if(sp == N + 1){ //cout << "EASY" << endl; if(N%2 == 0) ans = b; else ans = L-b; } else if(sp%2 == 1 && A[sp] - c >= b){ ans = b; } else if(sp%2 == 0 && A[sp] - c >= L-b){ ans = L-b; } else{ // cout << "HARDEST" << endl; RQS preq = RQe(); if(sp != 0) preq = (sp%2 == 1) ? RQ_moveCCW(A[sp]-c) : RQ_moveCW(A[sp]-c); int spr = G.max_right(sp,[preq,b](RQS q)->bool { RQS qq = RQop(preq,q); return -b < qq.mindx && qq.maxdx < L-b; }); //cout << "spr = " << spr << endl; preq = RQop(preq,G.prod(sp,spr)); //cout << "preq = (" << preq.minx << ", " << preq.maxx << ", " << preq.mindx << ", " << preq.maxdx << ", " << preq.dx << ")" << endl; sp = spr; if(spr % 2 == 0) ans = (A[spr] - c) + (b + (preq.dx - preq.maxx)); else ans = (A[spr] - c) + ((L-b) - (preq.dx - preq.minx)); } queryKey_D = ans; cout << ans << "\n"; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;