Submission #1751520
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=3e5+5,M=5e3+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);}
int r[N],x,K;
int main(){//judge();
read(x,K);
rep(i,1,K)read(r[i]);
int sgn=-1,pt=1,aa=0,bb=x,lover=0;
int Q=read();rep(cas,1,Q){
int t,a;read(t,a);
while(t>=r[pt]&&pt<=K){
int dt=sgn*(r[pt]-r[pt-1]);lover+=dt;
aa+=dt;gmin(aa,x);gmax(aa,0);
bb+=dt;gmin(bb,x);gmax(bb,0);
pt++;sgn=-sgn;
}
int res=lover+a;
gmin(res,bb);gmax(res,aa);
res+=sgn*(t-r[pt-1]);
gmin(res,x);gmax(res,0);
cout<<res<<endl;
}
}
Submission Info
Submission Time |
|
Task |
F - Sandglass |
User |
xjt |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
2341 Byte |
Status |
AC |
Exec Time |
284 ms |
Memory |
1536 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_000.txt, 0_001.txt, 0_002.txt |
All |
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt |
Case Name |
Status |
Exec Time |
Memory |
0_000.txt |
AC |
1 ms |
256 KB |
0_001.txt |
AC |
1 ms |
256 KB |
0_002.txt |
AC |
1 ms |
256 KB |
1_003.txt |
AC |
164 ms |
768 KB |
1_004.txt |
AC |
167 ms |
768 KB |
1_005.txt |
AC |
169 ms |
768 KB |
1_006.txt |
AC |
163 ms |
896 KB |
1_007.txt |
AC |
167 ms |
896 KB |
1_008.txt |
AC |
169 ms |
896 KB |
1_009.txt |
AC |
164 ms |
896 KB |
1_010.txt |
AC |
170 ms |
896 KB |
1_011.txt |
AC |
169 ms |
896 KB |
1_012.txt |
AC |
168 ms |
1024 KB |
1_013.txt |
AC |
168 ms |
1024 KB |
1_014.txt |
AC |
170 ms |
1024 KB |
1_015.txt |
AC |
169 ms |
1152 KB |
1_016.txt |
AC |
169 ms |
1152 KB |
1_017.txt |
AC |
171 ms |
1024 KB |
1_018.txt |
AC |
284 ms |
1152 KB |
1_019.txt |
AC |
170 ms |
1152 KB |
1_020.txt |
AC |
175 ms |
1152 KB |
1_021.txt |
AC |
170 ms |
1152 KB |
1_022.txt |
AC |
170 ms |
1280 KB |
1_023.txt |
AC |
174 ms |
1280 KB |
1_024.txt |
AC |
171 ms |
1152 KB |
1_025.txt |
AC |
174 ms |
1408 KB |
1_026.txt |
AC |
182 ms |
1408 KB |
1_027.txt |
AC |
172 ms |
1152 KB |
1_028.txt |
AC |
171 ms |
1280 KB |
1_029.txt |
AC |
175 ms |
1536 KB |
1_030.txt |
AC |
173 ms |
1152 KB |
1_031.txt |
AC |
176 ms |
1152 KB |
1_032.txt |
AC |
176 ms |
1536 KB |
1_033.txt |
AC |
168 ms |
1024 KB |
1_034.txt |
AC |
167 ms |
1024 KB |
1_035.txt |
AC |
173 ms |
1408 KB |
1_036.txt |
AC |
171 ms |
1152 KB |
1_037.txt |
AC |
167 ms |
1152 KB |
1_038.txt |
AC |
175 ms |
1536 KB |
1_039.txt |
AC |
168 ms |
896 KB |
1_040.txt |
AC |
167 ms |
1152 KB |
1_041.txt |
AC |
189 ms |
1536 KB |