結果

問題 No.510 二次漸化式
ユーザー ixmelixmel
提出日時 2017-04-08 13:36:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 566 ms / 3,000 ms
コード長 2,804 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 112,900 KB
実行使用メモリ 87,280 KB
最終ジャッジ日時 2023-09-24 23:24:36
合計ジャッジ時間 14,509 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 187 ms
4,376 KB
testcase_03 AC 187 ms
4,380 KB
testcase_04 AC 187 ms
4,380 KB
testcase_05 AC 185 ms
4,376 KB
testcase_06 AC 287 ms
13,568 KB
testcase_07 AC 291 ms
13,564 KB
testcase_08 AC 294 ms
13,568 KB
testcase_09 AC 297 ms
13,572 KB
testcase_10 AC 82 ms
4,380 KB
testcase_11 AC 82 ms
4,376 KB
testcase_12 AC 82 ms
4,380 KB
testcase_13 AC 82 ms
4,376 KB
testcase_14 AC 82 ms
4,380 KB
testcase_15 AC 82 ms
4,376 KB
testcase_16 AC 308 ms
87,260 KB
testcase_17 AC 312 ms
87,128 KB
testcase_18 AC 314 ms
87,084 KB
testcase_19 AC 309 ms
87,084 KB
testcase_20 AC 307 ms
87,140 KB
testcase_21 AC 315 ms
87,208 KB
testcase_22 AC 308 ms
87,060 KB
testcase_23 AC 503 ms
87,280 KB
testcase_24 AC 506 ms
87,128 KB
testcase_25 AC 510 ms
87,136 KB
testcase_26 AC 504 ms
87,124 KB
testcase_27 AC 496 ms
87,188 KB
testcase_28 AC 478 ms
87,188 KB
testcase_29 AC 481 ms
87,248 KB
testcase_30 AC 513 ms
87,212 KB
testcase_31 AC 561 ms
87,256 KB
testcase_32 AC 555 ms
87,088 KB
testcase_33 AC 566 ms
87,136 KB
testcase_34 AC 405 ms
87,188 KB
testcase_35 AC 330 ms
87,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=1e16;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define MOD 1000000007
typedef vvi SegT;
vvi defvalue;
vvi defvalue2;
SegT f(SegT A,SegT B){
	vvi C(A.size(),vi(B[0].size()));
	rep(i,A.size())rep(k,B.size())rep(j,B[0].size())
		(C[i][j]+=A[i][k]*B[k][j])%=MOD;
	return C;
}
class SegTree{
	private:
		vector<SegT>val;
		int n;
		SegT combine(SegT a,SegT b){return f(b,a);}
	public:
		SegTree(int size){
			n=1;
			while(n<size)n<<=1;
			val=vector<SegT>(2*n,defvalue);
		}
		SegTree(const vector<SegT> &in){
			n=1;
			while(n<in.size())n<<=1;
			val=vector<SegT>(2*n,defvalue);
			for(int i=n-1+in.size()-1;i>=0;i--){
				if(n-1<=i)val[i]=in[i-(n-1)];
				else val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		void update(int q,int i,ll a){
			i+=n-1;
			if(!q)val[i][0][2]=a;
			else{
				val[i][1][1]=a;
				val[i][2][1]=2*a;
				val[i][2][2]=a*a%MOD;
			}
			while(i>0){
				i=(i-1)/2;
				val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		SegT query(int a,int b,int k=0,int l=0,int r=-1){//[a,b)
			if(r==-1)r=n;
			if(r<=a||b<=l)return defvalue2;
			if(a<=l&&r<=b)return val[k];
			else return combine(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
		}
		void tmp(){
			rep(i,val.size()){
				cout<<i<<endl;
				rep(j,4){rep(k,4)cout<<" "<<val[i][j][k];cout<<endl;}
				cout<<endl;
			}
		}
};
int main(){
	vvi r=vvi(4,vi(4));
	r[0][0]=r[1][3]=r[2][3]=r[3][3]=1;
	defvalue=r;
	r=vvi(4,vi(4));
	r[0][0]=r[1][1]=r[2][2]=r[3][3]=1;
	defvalue2=r;
	int n,q;
	cin>>n>>q;
	SegTree st(n+1);
	assert(1<=n&&n<=100000);
	assert(1<=q&&q<=20000);
	int x,y;
	while(q--){
//		st.tmp();
		int a,b;
		char c;
		cin>>c;
		if(c=='x'){
			cin>>a>>b;
			assert(0<=a&&a<n);
			assert(0<=b&&b<=100000);
			st.update(0,a,b);
		}else if(c=='y'){
			cin>>a>>b;
			assert(0<=a&&a<n);
			assert(0<=b&&b<=100000);
			st.update(1,a,b);
		}else if(c=='a'){
			cin>>a;
			assert(0<=a&&a<=n);
			vvi t=st.query(0,a);
			cout<<(t[0][0]+t[0][1]+t[0][2]+t[0][3])%MOD<<endl;
		}else assert(-1);
	}
}






0