結果
問題 | No.749 クエリ全部盛り |
ユーザー | nebukuro09 |
提出日時 | 2018-10-19 22:47:17 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,974 bytes |
コンパイル時間 | 2,357 ms |
コンパイル使用メモリ | 208,320 KB |
実行使用メモリ | 61,184 KB |
最終ジャッジ日時 | 2024-11-18 21:58:33 |
合計ジャッジ時間 | 24,661 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
26,604 KB |
testcase_01 | AC | 17 ms
24,576 KB |
testcase_02 | AC | 18 ms
24,704 KB |
testcase_03 | AC | 17 ms
60,160 KB |
testcase_04 | AC | 18 ms
24,576 KB |
testcase_05 | AC | 24 ms
61,056 KB |
testcase_06 | AC | 25 ms
24,704 KB |
testcase_07 | AC | 24 ms
61,184 KB |
testcase_08 | AC | 25 ms
24,576 KB |
testcase_09 | AC | 25 ms
19,328 KB |
testcase_10 | AC | 210 ms
19,328 KB |
testcase_11 | AC | 209 ms
19,456 KB |
testcase_12 | AC | 210 ms
19,456 KB |
testcase_13 | AC | 210 ms
19,328 KB |
testcase_14 | AC | 210 ms
19,328 KB |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for (int i=0;i<(n);i++) #define REP2(i,m,n) for (int i=m;i<(n);i++) typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const int SIZE = 1000; int N, Q, q, l, r, k, s, t; ll A[SIZE]; ll B[SIZE * SIZE]; vector<vector<int>> C[SIZE]; ll F[1010101]; ll G[1010101]; void calc(int seg) { A[seg] = 0; int i = seg * SIZE; int v = min(i + SIZE, N); ll len = v - i; REP2(j, i, v) { REP(m, (int)C[seg].size()) { int type = C[seg][m][0]; ll x = C[seg][m][1]; if (type == 1) { B[j] = x; } else if (type == 2) { B[j] = (B[j] + x) % MOD; } else if (type == 3) { B[j] = B[j] * x % MOD; } else if (type == 4) { B[j] = (B[j] + F[j] * x % MOD) % MOD; } } A[seg] = (A[seg] + B[j]) % MOD; } C[seg].clear(); } void solve0() { ll ans = 0; REP2(seg, s, t+1) { int i = seg * SIZE; int v = min(i + SIZE, N); ll len = v - i; if (i < l || v > r) { calc(seg); REP2(j, max(i, l), min(v, r + 1)) { ans = (ans + B[j]) % MOD; } } else { ans = (ans + A[seg]) % MOD; } } ans = ans * k % MOD; ans = (ans + MOD) % MOD; printf("%lld\n", ans); } void solve1() { REP2(seg, s, t+1) { int i = seg * SIZE; int v = min(i + SIZE, N); ll len = v - i; if (i < l || v > r) { calc(seg); REP2(j, max(i, l), min(v, r + 1)) { A[seg] = (A[seg] - B[j]) % MOD; B[j] = k; A[seg] = (A[seg] + B[j]) % MOD; } } else { A[seg] = k * len % MOD; C[seg].push_back({1, k}); } } } void solve2() { REP2(seg, s, t+1) { int i = seg * SIZE; int v = min(i + SIZE, N); ll len = v - i; if (i < l || v > r) { calc(seg); REP2(j, max(i, l), min(v, r + 1)) { A[seg] = (A[seg] - B[j]) % MOD; B[j] = (B[j] + k) % MOD; A[seg] = (A[seg] + B[j]) % MOD; } } else { A[seg] = (A[seg] + k * len % MOD) % MOD; C[seg].push_back({2, k}); } } } void solve3() { REP2(seg, s, t+1) { int i = seg * SIZE; int v = min(i + SIZE, N); ll len = v - i; if (i < l || v > r) { calc(seg); REP2(j, max(i, l), min(v, r + 1)) { A[seg] = (A[seg] - B[j]) % MOD; B[j] = B[j] * k % MOD; A[seg] = (A[seg] + B[j]) % MOD; } } else { A[seg] = A[seg] * k % MOD; C[seg].push_back({3, k}); } } } void solve4() { REP2(seg, s, t+1) { int i = seg * SIZE; int v = min(i + SIZE, N); ll len = v - i; if (i < l || v > r) { calc(seg); REP2(j, max(i, l), min(v, r + 1)) { A[seg] = (A[seg] - B[j]) % MOD; B[j] = (B[j] + k * F[j] % MOD) % MOD; A[seg] = (A[seg] + B[j]) % MOD; } } else { A[seg] = (A[seg] + (G[v] - G[i]) * k % MOD) % MOD; C[seg].push_back({4, k}); } } } int main() { F[1] = 1; REP(i, 1000100) { F[i+2] = (F[i+1] + F[i]) % MOD; } REP(i, 1000100) { G[i+1] = (G[i] + F[i]) % MOD; } scanf("%d %d", &N, &Q); while (Q--) { scanf("%d %d %d %d", &q, &l, &r, &k); s = l / SIZE; t = r / SIZE; if (q == 0) solve0(); else if (q == 1) solve1(); else if (q == 2) solve2(); else if (q == 3) solve3(); else if (q == 4) solve4(); //REP(i, N) printf("%lld ", B[i]); //printf("\n"); } }