結果
| 問題 |
No.510 二次漸化式
|
| ユーザー |
|
| 提出日時 | 2017-04-29 01:02:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,634 bytes |
| コンパイル時間 | 930 ms |
| コンパイル使用メモリ | 79,072 KB |
| 実行使用メモリ | 15,368 KB |
| 最終ジャッジ日時 | 2024-09-13 18:57:07 |
| 合計ジャッジ時間 | 8,707 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 14 TLE * 1 -- * 19 |
ソースコード
#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;
}