結果

問題 No.510 二次漸化式
ユーザー gyosibgyosib
提出日時 2017-04-29 01:02:31
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,634 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 78,724 KB
実行使用メモリ 12,860 KB
最終ジャッジ日時 2023-10-11 20:07:02
合計ジャッジ時間 9,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<sstream>
#include<typeinfo>

using namespace std;

const long MOD = 1000000000 + 7;

void makes(vector<vector<long>> &v,vector<vector<long>> &xy, long index){
	if(index < v[0].size()){
		v[1][index] = (xy[1][index-1]*v[1][index-1] + 1) % MOD;
		v[0][index] = (xy[0][index-1]*(v[1][index-1] * (v[1][index-1]) % MOD) + v[0][index-1]) % MOD;
		makes(v,xy,++index);
	}
}

vector<string> split(string &str, char sep){
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while(std::getline(ss, buffer, sep)) {
        v.push_back(buffer);
    }
    return v;
}

int main(){
	long n, q;
	cin >> n >> q;
	string query_tmp;
  vector<string> query;
  vector<vector<long>> zenka(2,vector<long>(n+1,0));
  vector<vector<long>> xy(2,vector<long>(n+1,0));
  vector<long> res;
	long a0 = 1, b0 = 1;
	zenka[0][0] = a0, zenka[1][0] = b0;
	makes(zenka,xy,1);

	for(long i=0;i<q;i++){
		cin >> query_tmp;
		query.push_back(query_tmp);
		if(query_tmp == "a"){
			cin >> query_tmp;
			query.push_back(query_tmp);
		}else{
			cin >> query_tmp;
			query.push_back(query_tmp);
			cin >> query_tmp;
			query.push_back(query_tmp);
		}
	}
	
	for(long i=0;i<query.size();i++){
		if(query[i] == "a"){
			res.push_back(zenka[0][stoi(query[++i])] % (1000000000 + 7));
		}else if(query[i] == "x"){
			xy[0][stoi(query[++i])] = stoi(query[++i]);
		}else if(query[i] == "y"){
			xy[1][stoi(query[++i])] = stoi(query[++i]);
		}
	
		makes(zenka,xy,1);
	}

	for(long a:res){
		cout << a << endl;
	}
	
	return 0;
}
  
0