Submission #1555296


Source Code Expand

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll T;
int K,Q;

int main(){
	cin>>T;
	cin>>K;
	set<P> events;
	rep(i,K){
		int t;
		cin>>t;
		events.insert(P(t,-1));	//reverse query
	}
	cin>>Q;
	rep(i,Q){
		ll t,f;
		cin>>t>>f;
		events.insert(P(t,f));
	}

	bool inc = 0;
	ll pt = 0;
	ll a = 0, b = T, c = 0;
	for(P e:events){
		ll t = e.fs;
		ll x = e.sc;

		if(inc){
			ll d = t-pt;
			c += d;
			if(b+c>T) b = T-c;
			if(a>b) a = b;
		}else{
			ll d = t-pt;
			c -= d;
			if(a+c<0) a = -c;
			if(a>b) b = a;
		}
		if(x==-1){	//reverse
			inc = !inc;
		}else{		//answer
			cout<<max(a,min(b,x))+c<<endl;
		}
		pt = t;
	}
}

Submission Info

Submission Time
Task F - Sandglass
User sigma425
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1018 Byte
Status AC
Exec Time 334 ms
Memory 13696 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 42
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 280 ms 12928 KB
1_004.txt AC 292 ms 12928 KB
1_005.txt AC 300 ms 12928 KB
1_006.txt AC 290 ms 12928 KB
1_007.txt AC 289 ms 12928 KB
1_008.txt AC 302 ms 12928 KB
1_009.txt AC 284 ms 13056 KB
1_010.txt AC 295 ms 13056 KB
1_011.txt AC 301 ms 13056 KB
1_012.txt AC 288 ms 13056 KB
1_013.txt AC 297 ms 13056 KB
1_014.txt AC 314 ms 13056 KB
1_015.txt AC 293 ms 13184 KB
1_016.txt AC 298 ms 13184 KB
1_017.txt AC 313 ms 13184 KB
1_018.txt AC 291 ms 13312 KB
1_019.txt AC 303 ms 13312 KB
1_020.txt AC 317 ms 13312 KB
1_021.txt AC 316 ms 13312 KB
1_022.txt AC 307 ms 13440 KB
1_023.txt AC 316 ms 13440 KB
1_024.txt AC 319 ms 13184 KB
1_025.txt AC 308 ms 13568 KB
1_026.txt AC 322 ms 13568 KB
1_027.txt AC 328 ms 13312 KB
1_028.txt AC 330 ms 13312 KB
1_029.txt AC 322 ms 13568 KB
1_030.txt AC 334 ms 13312 KB
1_031.txt AC 334 ms 13312 KB
1_032.txt AC 329 ms 13696 KB
1_033.txt AC 254 ms 7296 KB
1_034.txt AC 240 ms 7296 KB
1_035.txt AC 319 ms 13440 KB
1_036.txt AC 258 ms 7424 KB
1_037.txt AC 247 ms 7424 KB
1_038.txt AC 320 ms 13568 KB
1_039.txt AC 261 ms 7168 KB
1_040.txt AC 250 ms 7552 KB
1_041.txt AC 325 ms 13696 KB