結果
問題 | No.1568 Sushi |
ユーザー | blackyuki |
提出日時 | 2021-04-17 14:36:40 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 808 ms / 2,000 ms |
コード長 | 4,263 bytes |
コンパイル時間 | 2,690 ms |
コンパイル使用メモリ | 217,936 KB |
実行使用メモリ | 179,248 KB |
最終ジャッジ日時 | 2024-06-25 10:02:33 |
合計ジャッジ時間 | 21,118 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 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 | 13 ms
7,168 KB |
testcase_05 | AC | 9 ms
5,376 KB |
testcase_06 | AC | 11 ms
5,660 KB |
testcase_07 | AC | 8 ms
5,376 KB |
testcase_08 | AC | 11 ms
7,040 KB |
testcase_09 | AC | 651 ms
139,076 KB |
testcase_10 | AC | 561 ms
99,948 KB |
testcase_11 | AC | 552 ms
104,624 KB |
testcase_12 | AC | 516 ms
101,992 KB |
testcase_13 | AC | 623 ms
137,564 KB |
testcase_14 | AC | 520 ms
95,204 KB |
testcase_15 | AC | 687 ms
170,760 KB |
testcase_16 | AC | 515 ms
98,236 KB |
testcase_17 | AC | 789 ms
177,996 KB |
testcase_18 | AC | 760 ms
132,632 KB |
testcase_19 | AC | 619 ms
138,944 KB |
testcase_20 | AC | 533 ms
98,696 KB |
testcase_21 | AC | 608 ms
132,168 KB |
testcase_22 | AC | 598 ms
122,308 KB |
testcase_23 | AC | 808 ms
165,240 KB |
testcase_24 | AC | 629 ms
123,228 KB |
testcase_25 | AC | 652 ms
151,240 KB |
testcase_26 | AC | 688 ms
167,544 KB |
testcase_27 | AC | 726 ms
179,248 KB |
testcase_28 | AC | 658 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 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(){ 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=readll(),t=readll(); 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); } }