結果

問題 No.510 二次漸化式
ユーザー latte0119latte0119
提出日時 2017-04-28 23:28:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 266 ms / 3,000 ms
コード長 1,145 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 148,616 KB
実行使用メモリ 6,288 KB
最終ジャッジ日時 2023-10-11 19:45:13
合計ジャッジ時間 6,791 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 55 ms
4,348 KB
testcase_03 AC 55 ms
4,352 KB
testcase_04 AC 55 ms
4,352 KB
testcase_05 AC 55 ms
4,356 KB
testcase_06 AC 147 ms
4,352 KB
testcase_07 AC 145 ms
4,352 KB
testcase_08 AC 145 ms
4,352 KB
testcase_09 AC 146 ms
4,348 KB
testcase_10 AC 21 ms
4,352 KB
testcase_11 AC 21 ms
4,348 KB
testcase_12 AC 21 ms
4,352 KB
testcase_13 AC 21 ms
4,348 KB
testcase_14 AC 21 ms
4,348 KB
testcase_15 AC 21 ms
4,352 KB
testcase_16 AC 69 ms
5,964 KB
testcase_17 AC 68 ms
6,120 KB
testcase_18 AC 66 ms
6,112 KB
testcase_19 AC 65 ms
6,084 KB
testcase_20 AC 66 ms
6,084 KB
testcase_21 AC 68 ms
6,024 KB
testcase_22 AC 68 ms
6,184 KB
testcase_23 AC 263 ms
6,188 KB
testcase_24 AC 266 ms
5,964 KB
testcase_25 AC 259 ms
6,288 KB
testcase_26 AC 263 ms
6,212 KB
testcase_27 AC 253 ms
6,108 KB
testcase_28 AC 260 ms
6,128 KB
testcase_29 AC 260 ms
5,968 KB
testcase_30 AC 257 ms
6,040 KB
testcase_31 AC 25 ms
5,260 KB
testcase_32 AC 26 ms
5,496 KB
testcase_33 AC 26 ms
6,036 KB
testcase_34 AC 35 ms
4,352 KB
testcase_35 AC 37 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int N,Q;

int X[111111],Y[111111];

int B[111111];
bool ex[111111];

signed main(){
    cin>>N>>Q;
    rep(i,N)B[i]=1;

    vint lis;
    rep(i,Q){
        char c;
        int k;
        cin>>c>>k;
        if(c=='x'||c=='y'){
            k++;
            if(c=='x')scanf("%lld",&X[k]);
            else scanf("%lld",&Y[k]);

            if(!ex[k]){
                lis.insert(lower_bound(all(lis),k),k);
            }
            ex[k]=true;
            continue;
        }
        int a=1;
        for(int j=0;j<lis.size()&&lis[j]<=k;j++){
            int l=lis[j];
            B[l]=(B[l-1]*Y[l]+1)%mod;
            a=(a+X[l]*B[l-1]%mod*B[l-1])%mod;
        }
        cout<<a<<endl;
    }
}
0