結果

問題 No.510 二次漸化式
ユーザー ixmelixmel
提出日時 2017-04-08 13:33:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,798 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 113,128 KB
実行使用メモリ 87,228 KB
最終ジャッジ日時 2023-09-24 23:22:28
合計ジャッジ時間 14,792 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 291 ms
13,632 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 305 ms
87,100 KB
testcase_17 AC 311 ms
87,092 KB
testcase_18 AC 317 ms
87,204 KB
testcase_19 AC 316 ms
87,200 KB
testcase_20 AC 318 ms
87,144 KB
testcase_21 AC 314 ms
87,148 KB
testcase_22 AC 316 ms
87,160 KB
testcase_23 AC 525 ms
87,112 KB
testcase_24 AC 515 ms
87,228 KB
testcase_25 AC 511 ms
87,144 KB
testcase_26 AC 525 ms
87,196 KB
testcase_27 AC 511 ms
87,108 KB
testcase_28 AC 526 ms
87,156 KB
testcase_29 AC 524 ms
87,140 KB
testcase_30 AC 511 ms
87,164 KB
testcase_31 AC 570 ms
87,112 KB
testcase_32 AC 568 ms
87,112 KB
testcase_33 AC 559 ms
87,152 KB
testcase_34 AC 408 ms
87,164 KB
testcase_35 AC 332 ms
87,100 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]<<endl;
		}else assert(-1);
	}
}






0