結果
問題 | No.1568 Sushi |
ユーザー | blackyuki |
提出日時 | 2021-04-17 14:35:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,052 ms / 2,000 ms |
コード長 | 4,063 bytes |
コンパイル時間 | 2,987 ms |
コンパイル使用メモリ | 217,284 KB |
実行使用メモリ | 179,372 KB |
最終ジャッジ日時 | 2024-06-25 10:01:06 |
合計ジャッジ時間 | 24,759 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 14 ms
7,168 KB |
testcase_05 | AC | 9 ms
5,376 KB |
testcase_06 | AC | 11 ms
5,632 KB |
testcase_07 | AC | 9 ms
5,376 KB |
testcase_08 | AC | 13 ms
6,912 KB |
testcase_09 | AC | 855 ms
139,072 KB |
testcase_10 | AC | 732 ms
99,868 KB |
testcase_11 | AC | 695 ms
104,496 KB |
testcase_12 | AC | 659 ms
101,988 KB |
testcase_13 | AC | 779 ms
137,436 KB |
testcase_14 | AC | 660 ms
95,220 KB |
testcase_15 | AC | 926 ms
170,632 KB |
testcase_16 | AC | 689 ms
98,104 KB |
testcase_17 | AC | 1,052 ms
177,864 KB |
testcase_18 | AC | 808 ms
132,636 KB |
testcase_19 | AC | 811 ms
138,948 KB |
testcase_20 | AC | 697 ms
98,564 KB |
testcase_21 | AC | 835 ms
132,168 KB |
testcase_22 | AC | 786 ms
122,312 KB |
testcase_23 | AC | 932 ms
165,112 KB |
testcase_24 | AC | 775 ms
123,100 KB |
testcase_25 | AC | 889 ms
151,108 KB |
testcase_26 | AC | 979 ms
167,412 KB |
testcase_27 | AC | 977 ms
179,372 KB |
testcase_28 | AC | 775 ms
116,456 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 res;cin>>res;return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll L=readll(),n=readll(),q=readll(); assert(1<=L); assert(L<=cons); assert(1<=n); assert(n<=200000); assert(1<=q); assert(1<=200000); vi difpoint(n+3);rep(i,n)difpoint[i+1]=readll();difpoint[n+1]=inf/2;difpoint[n+2]=inf; rep(i,n)assert(1<=difpoint[i+1]&&difpoint[i+1]<=cons); rep(i,n-1)assert(difpoint[i+1]<difpoint[i+2]); 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; assert(0<=x&&x<L);assert(0<=t&&t<cons); 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); } }