結果
問題 |
No.510 二次漸化式
|
ユーザー |
![]() |
提出日時 | 2017-04-29 00:19:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,408 bytes |
コンパイル時間 | 1,609 ms |
コンパイル使用メモリ | 167,212 KB |
実行使用メモリ | 8,292 KB |
最終ジャッジ日時 | 2024-09-13 19:38:22 |
合計ジャッジ時間 | 5,534 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 WA * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) #define ALL(x) x.begin(),x.end() template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; int N,Q; const int BUCKET = 500,SIZE = 491; ll add [BUCKET]; ll B [BUCKET * SIZE]; ll X [BUCKET * SIZE],Y [BUCKET * SIZE]; const ll MOD = 1e9 + 7; ll get(ll r) { ll res = 1; for(int i = 0;i < BUCKET;i++){ if(SIZE * (i + 1) <= r){ (res += add [i]) %= MOD; continue; } for(int j = SIZE * i;j < r;j++){ (res += X [j] * (B [j] * B [j] % MOD)) %= MOD; } break; } return res; } void update(ll idx) { for(ll i = idx / SIZE * SIZE;i < (idx / SIZE + 1) * SIZE && i < N;i++){ B [i + 1] = (B [i] * Y [i] + 1) % MOD; } add [idx / SIZE] = 0; for(ll i = idx / SIZE * SIZE;i < (idx / SIZE + 1) * SIZE && i < N;i++){ (add [idx / SIZE] += X [i] * (B [i] * B [i] % MOD)) %= MOD; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> Q; for(ll i = 0;i <= N;i++){ B [i] = 1; } FOR(i,0,Q){ char c; ll p,q; cin >> c; if(c == 'a'){ cin >> p; cout << get(p) << endl; } else if(c == 'y'){ cin >> p >> q; Y [p] = q; update(p); } else{ cin >> p >> q; X [p] = q; update(p); } } return 0; }