結果

問題 No.510 二次漸化式
ユーザー Dameningen
提出日時 2017-04-29 00:10:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,706 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 89,428 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-09-13 19:33:11
合計ジャッジ時間 47,287 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 11 WA * 13 TLE * 9 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<cassert>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX_N = 100000, MAX_Q = 20000, MOD = 1e9 + 7;


int main()
{
    int n, q;
    static ll a[MAX_N+1], b[MAX_N+1];
    static int x[MAX_N+1], y[MAX_N+1];
    a[0] = 1; b[0] = 1;
    
    cin >> n >> q;
    
    static char query[MAX_Q];
    static int i[MAX_Q], v[MAX_Q];
    
    
    rep(s, q) {
        cin >> query[s];
        if (query[s] == 'x') {
            cin >> i[s] >> v[s];
        } else if (query[s] == 'y') {
            cin >> i[s] >> v[s];
        } else {
            cin >> i[s];
        }
    }
    
    
    
    rep(s, q) {
        
        if (query[s] == 'x') {
            x[i[s]] = v[s];
        } else if (query[s] == 'y') {
            y[i[s]] = v[s];
        } else {
            
            if (i[s] == 0) {
                cout << 1 << endl;
            }
            
            reps(j, 1, i[s]+1) {
                a[j] = (((x[j-1] * b[j-1]) % MOD) * b[j-1] + a[j-1]) % MOD;
                b[j] = (y[j-1] * b[j-1] + 1) % MOD;
            }
            
            cout << a[i[s]] << endl;
        }
    }
    
    return 0;
}
0