結果
問題 | No.1568 Sushi |
ユーザー | blackyuki |
提出日時 | 2021-04-17 14:23:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,440 ms / 2,000 ms |
コード長 | 3,549 bytes |
コンパイル時間 | 2,415 ms |
コンパイル使用メモリ | 213,952 KB |
実行使用メモリ | 197,832 KB |
最終ジャッジ日時 | 2024-06-25 10:00:39 |
合計ジャッジ時間 | 31,589 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 25 ms
7,552 KB |
testcase_05 | AC | 19 ms
5,376 KB |
testcase_06 | AC | 23 ms
5,760 KB |
testcase_07 | AC | 21 ms
5,376 KB |
testcase_08 | AC | 25 ms
7,424 KB |
testcase_09 | AC | 1,245 ms
153,484 KB |
testcase_10 | AC | 1,138 ms
110,084 KB |
testcase_11 | AC | 1,078 ms
115,368 KB |
testcase_12 | AC | 1,084 ms
112,420 KB |
testcase_13 | AC | 1,207 ms
151,820 KB |
testcase_14 | AC | 1,033 ms
105,020 KB |
testcase_15 | AC | 1,303 ms
188,424 KB |
testcase_16 | AC | 1,128 ms
108,084 KB |
testcase_17 | AC | 1,440 ms
196,428 KB |
testcase_18 | AC | 1,202 ms
146,296 KB |
testcase_19 | AC | 1,221 ms
153,360 KB |
testcase_20 | AC | 1,102 ms
108,536 KB |
testcase_21 | AC | 1,215 ms
145,824 KB |
testcase_22 | AC | 1,159 ms
134,892 KB |
testcase_23 | AC | 1,296 ms
182,292 KB |
testcase_24 | AC | 1,169 ms
135,956 KB |
testcase_25 | AC | 1,256 ms
166,888 KB |
testcase_26 | AC | 1,311 ms
184,888 KB |
testcase_27 | AC | 1,418 ms
197,832 KB |
testcase_28 | AC | 1,161 ms
128,424 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #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; 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';} class sparsetable{ vi tmp; vvi Lmi,Rmi,Lma,Rma; vi rng; public: sparsetable(vi v){ rng.resize(v.size()+1); rep(c,20)REP(i,1<<c,1<<(c+1))if(i<=v.size())rng[i]=c; Lmi=vvi(20,vi(v.size())); Lma=vvi(20,vi(v.size())); Rmi=vvi(20,vi(v.size())); Rma=vvi(20,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,19)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]); } }; int main(){ // cin.tie(0);ios::sync_with_stdio(false); ll L,n,q;cin>>L>>n>>q; vi difpoint(n+3);rep(i,n)cin>>difpoint[i+1];difpoint[n+1]=inf/2;difpoint[n+2]=inf; n+=3; vvi tablema(20,vi(n)),tablemi(20,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,19)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);assert(d>=0); ans=difpoint[ok]-d; ll r=idx; for(int c=19;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));assert(d>=0); chmin(ans,difpoint[r]-d); ans-=t; out(ans); } }