結果
問題 | No.1568 Sushi |
ユーザー | blackyuki |
提出日時 | 2021-04-17 14:28:14 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,561 ms / 2,000 ms |
コード長 | 3,927 bytes |
コンパイル時間 | 2,666 ms |
コンパイル使用メモリ | 216,092 KB |
実行使用メモリ | 179,224 KB |
最終ジャッジ日時 | 2024-06-25 10:02:09 |
合計ジャッジ時間 | 34,105 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 24 ms
7,168 KB |
testcase_05 | AC | 20 ms
5,376 KB |
testcase_06 | AC | 22 ms
5,632 KB |
testcase_07 | AC | 20 ms
5,376 KB |
testcase_08 | AC | 23 ms
7,168 KB |
testcase_09 | AC | 1,324 ms
139,048 KB |
testcase_10 | AC | 1,210 ms
100,180 KB |
testcase_11 | AC | 1,186 ms
104,604 KB |
testcase_12 | AC | 1,170 ms
101,968 KB |
testcase_13 | AC | 1,294 ms
137,540 KB |
testcase_14 | AC | 1,151 ms
95,192 KB |
testcase_15 | AC | 1,429 ms
170,612 KB |
testcase_16 | AC | 1,200 ms
98,084 KB |
testcase_17 | AC | 1,561 ms
177,840 KB |
testcase_18 | AC | 1,344 ms
132,608 KB |
testcase_19 | AC | 1,306 ms
138,920 KB |
testcase_20 | AC | 1,185 ms
98,676 KB |
testcase_21 | AC | 1,292 ms
132,148 KB |
testcase_22 | AC | 1,301 ms
122,288 KB |
testcase_23 | AC | 1,384 ms
165,084 KB |
testcase_24 | AC | 1,310 ms
123,204 KB |
testcase_25 | AC | 1,339 ms
151,212 KB |
testcase_26 | AC | 1,431 ms
167,388 KB |
testcase_27 | AC | 1,496 ms
179,224 KB |
testcase_28 | AC | 1,227 ms
116,304 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) typedef long long ll; #define all(a) a.begin(),a.end() #define lb(v,k) (lower_bound(all(v),(k))-v.begin()) ll cons=1000000000000000; ll inf=1001001001001001001; ll lg=18; using vi=vector<ll>; using vvi=vector<vi>; typedef pair<ll,ll> P; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.first<<','<<a.second<<')'<<'\n';} class sparsetable{ vi tmp; vvi Lmi,Rmi,Lma,Rma; vi rng; public: sparsetable(vi v){ rng.resize(v.size()+1); rep(c,lg)REP(i,1<<c,1<<(c+1))if(i<=v.size())rng[i]=c; Lmi=vvi(lg,vi(v.size())); Lma=vvi(lg,vi(v.size())); Rmi=vvi(lg,vi(v.size())); Rma=vvi(lg,vi(v.size())); rep(i,v.size()){ Lmi[0][i]=v[i]; Lma[0][i]=v[i]; Rmi[0][i]=v[i]; Rma[0][i]=v[i]; } rep(c,lg-1)rep(i,v.size()){ ll ni=i+(1<<c); if(ni<v.size()){ Lmi[c+1][i]=min(Lmi[c][i],Lmi[c][ni]); Lma[c+1][i]=max(Lma[c][i],Lma[c][ni]); } ni=i-(1<<c); if(ni>=0){ Rmi[c+1][i]=min(Rmi[c][i],Rmi[c][ni]); Rma[c+1][i]=max(Rma[c][i],Rma[c][ni]); } } } ll mi(ll l,ll r){ if(l>=r)return inf; return min(Lmi[rng[r-l]][l],Rmi[rng[r-l]][r-1]); } ll ma(ll l,ll r){ if(l>=r)return -inf; return max(Lma[rng[r-l]][l],Rma[rng[r-l]][r-1]); } }; inline ll readll() { ll x = 0; char ch = getchar_unlocked(); while (ch < '0' || ch > '9') ch = getchar_unlocked(); while (ch >= '0' && ch <= '9'){ x = (x << 3) + (x << 1) + ch - '0'; ch = getchar_unlocked(); } return x; } int main(){ ll L=readll(),n=readll(),q=readll(); vi difpoint(n+3);rep(i,n)difpoint[i+1]=readll();difpoint[n+1]=inf/2;difpoint[n+2]=inf; n+=3; vvi tablema(lg,vi(n)),tablemi(lg,vi(n)); rep(i,n)tablema[0][i]=tablemi[0][i]=0; vi v(n); rep(i,n-1){ if(i%2)v[i+1]=v[i]-difpoint[i+1]+difpoint[i]; else v[i+1]=v[i]+difpoint[i+1]-difpoint[i]; } sparsetable sp(v); rep(c,lg-1)rep(i,n){ ll ni=i+(1<<c); tablema[c+1][i]=tablema[c][i]; tablemi[c+1][i]=tablemi[c][i]; if(ni<n){ chmax(tablema[c+1][i],tablema[c][ni]); chmin(tablemi[c+1][i],tablemi[c][ni]); ll nni=min(ni+(1<<c),n); chmax(tablema[c+1][i],sp.ma(ni,nni)-sp.mi(i,ni)); chmin(tablemi[c+1][i],sp.mi(ni,nni)-sp.ma(i,ni)); } } auto val=[&](ll t){ ll l=lb(difpoint,t); if(l%2)return v[l]-difpoint[l]+t; return v[l]+difpoint[l]-t; }; ll ans=0; rep(qq,q){ ll x,t;cin>>x>>t; x+=ans;t+=ans;x%=L;t%=cons; ll idx=lb(difpoint,t); ll cur=val(t); ll ok=n,ng=idx-1; while(ok-ng>1){ ll md=(ok+ng)/2; if(sp.ma(idx,md+1)-cur>=x||sp.mi(idx,md+1)-cur<=x-L)ok=md; else ng=md; } ll d=max(v[ok]-cur-x,x-L-v[ok]+cur); ans=difpoint[ok]-d; ll r=idx; for(int c=lg-1;c>=0;c--){ ll nr=r+(1<<c); ll ma=max(tablema[c][r],sp.ma(r,min(nr,n))-sp.mi(idx,r)); ll mi=min(tablemi[c][r],sp.mi(r,min(nr,n))-sp.ma(idx,r)); if(ma>=x||mi<=x-L)continue; r=nr; } d=max(v[r]-sp.mi(idx,r+1)-x,x-L-v[r]+sp.ma(idx,r+1)); chmin(ans,difpoint[r]-d); ans-=t; out(ans); } }