結果

問題 No.1568 Sushi
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-06-26 14:19:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,997 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 98,876 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 16:39:17
合計ジャッジ時間 6,937 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 24 ms
4,376 KB
testcase_05 AC 11 ms
4,376 KB
testcase_06 AC 15 ms
4,380 KB
testcase_07 AC 11 ms
4,376 KB
testcase_08 AC 31 ms
4,376 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


Int L;
int N, Q;
vector<Int> A;

Int solve(Int X, Int T) {
// cerr<<"solve "<<X<<" "<<T<<endl;
  const Int xp = -((L - X) % L), xq = X;
  Int p = 0, q = 0;
  const int i0 = upper_bound(A.begin(), A.end(), T) - A.begin();
  for (int i = i0 - 1; i <= N; ++i) {
    const Int a = max(A[i], T), b = A[i + 1];
    const Int len = b - a;
    if (i & 1) {
      if (p - len <= xp) {
        return a + (p - xp) - T;
      }
      p -= len;
      chmax(q -= len, 0LL);
    } else {
      if (xq <= q + len) {
        return a + (xq - q) - T;
      }
      chmin(p += len, 0LL);
      q += len;
    }
  }
  assert(false);
  return 0;
}

int main() {
  for (; ~scanf("%lld%d%d", &L, &N, &Q); ) {
    A.resize(N + 2);
    A[0] = 0;
    for (int i = 1; i <= N; ++i) {
      scanf("%lld", &A[i]);
    }
    A[N + 1] = A[N] + 2 * L;
    
    Int ans = 0;
    for (; Q--; ) {
      Int b, c;
      scanf("%lld%lld", &b, &c);
      const Int x = (b + ans) % L;
      const Int t = (c + ans) % 1'000'000'000'000'000LL;
      ans = solve(x, t);
      printf("%lld\n", ans);
    }
  }
  return 0;
}
0