結果

問題 No.510 二次漸化式
ユーザー Guowen Rong
提出日時 2025-02-24 17:09:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,518 ms / 3,000 ms
コード長 1,265 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 163,860 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-24 17:10:04
合計ジャッジ時間 23,989 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

 #include<bits/stdc++.h>
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define fi first
#define se second
#define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
using namespace std;
typedef __int128 __;
typedef long double lb;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
bool Begin;
inline ll read(){
    ll x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')
          f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return x * f;
}
inline void write(ll x){
	if(x < 0){
		putchar('-');
		x = -x;
	}
	if(x > 9)
	  write(x / 10);
	putchar(x % 10 + '0');
}
int N,Q;
ll X[101010];
ll Y[101010];
ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	N = read(), Q = read();
	while(Q--) {
		cin>>s;
		x = read();
		if(s=="x")
		  X[x] = read();
		else if(s=="y") 
		  Y[x] = read();
		else if(s=="a") {
			ll A=1,B=1;
			for(int i = 0; i < x; ++i){
				if(X[i]) (A += X[i]*B%mo*B)%=mo;
				if(Y[i]) B = (B*Y[i]+1)%mo;
				else B=1;
			}
			write(A);
			putchar('\n');
		}
	}
}
bool End;
int main(){
	solve();
	cerr << '\n' << abs(&Begin - &End) / 1048576 << "MB";
	return 0;
}
0