提出 #1816259


ソースコード 拡げる

#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int X,n,Q;

int R[maxn],c[maxn],l[maxn],r[maxn];

void Work(){
	read(Q);
	while(Q--){
		int t,a;
		read(t,a);
		int x=upper_bound(R+1,R+n+1,t)-R-1;
		int ans=a+c[x];
		ans=min(ans,r[x]);ans=max(ans,l[x]);
		if(x&1)ans+=t-R[x];else ans-=t-R[x];
		ans=min(ans,X);ans=max(ans,0);
		iout(ans);
	}
}

void Init(){
	read(X);
	read(n);
	REP(i,1,n)read(R[i]);
	l[0]=0;r[0]=X;c[0]=0;
	REP(i,1,n){
		int t;
		if(i&1)t=-1;else t=1;
		t*=(R[i]-R[i-1]);
		c[i]=c[i-1]+t;//c[i]=min(c[i],X);c[i]=max(c[i],-X);
		l[i]=l[i-1]+t;l[i]=min(l[i],X);l[i]=max(l[i],0);
		r[i]=r[i-1]+t;r[i]=min(r[i],X);r[i]=max(r[i],0);
	}
}

int main(){
	Init();
	Work();
	return 0;
}

提出情報

提出日時
問題 F - Sandglass
ユーザ yanQval
言語 C++14 (GCC 5.4.1)
得点 700
コード長 2309 Byte
結果 AC
実行時間 39 ms
メモリ 2816 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 700 / 700
結果
AC × 3
AC × 42
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
0_000.txt AC 1 ms 256 KiB
0_001.txt AC 1 ms 256 KiB
0_002.txt AC 1 ms 256 KiB
1_003.txt AC 26 ms 2048 KiB
1_004.txt AC 28 ms 2048 KiB
1_005.txt AC 30 ms 2048 KiB
1_006.txt AC 26 ms 2048 KiB
1_007.txt AC 28 ms 2048 KiB
1_008.txt AC 31 ms 2048 KiB
1_009.txt AC 27 ms 2048 KiB
1_010.txt AC 29 ms 2048 KiB
1_011.txt AC 31 ms 2048 KiB
1_012.txt AC 28 ms 2176 KiB
1_013.txt AC 29 ms 2176 KiB
1_014.txt AC 32 ms 2176 KiB
1_015.txt AC 28 ms 2304 KiB
1_016.txt AC 30 ms 2304 KiB
1_017.txt AC 34 ms 2176 KiB
1_018.txt AC 30 ms 2432 KiB
1_019.txt AC 31 ms 2432 KiB
1_020.txt AC 34 ms 2304 KiB
1_021.txt AC 30 ms 2304 KiB
1_022.txt AC 32 ms 2432 KiB
1_023.txt AC 35 ms 2432 KiB
1_024.txt AC 31 ms 2304 KiB
1_025.txt AC 33 ms 2560 KiB
1_026.txt AC 36 ms 2560 KiB
1_027.txt AC 32 ms 2304 KiB
1_028.txt AC 34 ms 2432 KiB
1_029.txt AC 39 ms 2816 KiB
1_030.txt AC 34 ms 2432 KiB
1_031.txt AC 35 ms 2432 KiB
1_032.txt AC 38 ms 2816 KiB
1_033.txt AC 23 ms 1152 KiB
1_034.txt AC 24 ms 1024 KiB
1_035.txt AC 34 ms 2560 KiB
1_036.txt AC 25 ms 1152 KiB
1_037.txt AC 26 ms 1152 KiB
1_038.txt AC 37 ms 2688 KiB
1_039.txt AC 25 ms 896 KiB
1_040.txt AC 27 ms 1280 KiB
1_041.txt AC 38 ms 2816 KiB