結果
問題 |
No.1568 Sushi
|
ユーザー |
👑 |
提出日時 | 2021-06-26 14:19:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,997 bytes |
コンパイル時間 | 923 ms |
コンパイル使用メモリ | 101,888 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-06-25 10:32:31 |
合計ジャッジ時間 | 6,674 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 5 TLE * 1 -- * 19 |
ソースコード
#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; }