Submission #1751971


Source Code Expand

// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int X , K , r[N];
int Q , t , a;

int main(){
    cin >> X >> K;
    rep(i,1,K+1) cin >> r[i];
    cin >> Q;
    int a = 0 , b = X , c = 0;
    int cur = 0;
    rep(i,0,Q) {
        int t , W;
        cin >> t >> W;
        while(cur < K && r[cur + 1] <= t) {
            int duration = r[cur + 1] - r[cur];
            if(cur & 1) {
                if(a + c + duration >= X) a = b = X , c = 0;
                else if(b + c + duration < X) c += duration;
                else b = X - duration - c , c = X - b;
            } else {
                if(b + c - duration <= 0) a = b = X , c = -X;
                else if(a + c - duration > 0) c -= duration;
                else a = duration - c , c = -a;
            }
            ++cur;
        }
        int fx = 0;
        if(W <= a) fx = a + c;
        else if(a < W && W < b) fx = W + c;
        else fx = b + c;
        if(cur & 1) printf("%d\n",min(X , fx + t - r[cur]));
        else printf("%d\n",max(0 , fx - t + r[cur]));
    }
    return 0;
}

Submission Info

Submission Time
Task F - Sandglass
User Y_UME
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1840 Byte
Status AC
Exec Time 326 ms
Memory 1536 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 255 ms 768 KB
1_004.txt AC 267 ms 768 KB
1_005.txt AC 289 ms 768 KB
1_006.txt AC 259 ms 896 KB
1_007.txt AC 270 ms 896 KB
1_008.txt AC 287 ms 896 KB
1_009.txt AC 263 ms 896 KB
1_010.txt AC 276 ms 896 KB
1_011.txt AC 289 ms 896 KB
1_012.txt AC 266 ms 1024 KB
1_013.txt AC 280 ms 1024 KB
1_014.txt AC 297 ms 1024 KB
1_015.txt AC 272 ms 1152 KB
1_016.txt AC 281 ms 1152 KB
1_017.txt AC 299 ms 1024 KB
1_018.txt AC 271 ms 1152 KB
1_019.txt AC 290 ms 1152 KB
1_020.txt AC 304 ms 1152 KB
1_021.txt AC 282 ms 1152 KB
1_022.txt AC 303 ms 1280 KB
1_023.txt AC 309 ms 1280 KB
1_024.txt AC 306 ms 1152 KB
1_025.txt AC 294 ms 1408 KB
1_026.txt AC 311 ms 1408 KB
1_027.txt AC 295 ms 1152 KB
1_028.txt AC 300 ms 1280 KB
1_029.txt AC 315 ms 1536 KB
1_030.txt AC 306 ms 1152 KB
1_031.txt AC 312 ms 1152 KB
1_032.txt AC 326 ms 1536 KB
1_033.txt AC 257 ms 1024 KB
1_034.txt AC 257 ms 1024 KB
1_035.txt AC 304 ms 1408 KB
1_036.txt AC 267 ms 1152 KB
1_037.txt AC 269 ms 1152 KB
1_038.txt AC 315 ms 1536 KB
1_039.txt AC 269 ms 896 KB
1_040.txt AC 275 ms 1280 KB
1_041.txt AC 326 ms 1536 KB