結果
| 問題 |
No.510 二次漸化式
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2017-04-29 00:01:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,709 bytes |
| コンパイル時間 | 1,080 ms |
| コンパイル使用メモリ | 100,372 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-13 18:46:59 |
| 合計ジャッジ時間 | 11,605 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 WA * 30 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
set<pair<long long, long long>> x;
set<pair<long long, long long>> y;
map<long long,long long> x_appear;
map<long long,long long> y_appear;
int main() {
#define int long long
long long n, query;
cin >> n >> query;
y.insert(make_pair(10000000, 0));
x.insert(make_pair(10000000, 0));
REP(test_case, query) {
string s;
cin >> s;
if (s == "a") {
long long a;
cin >> a;
auto xs = x.begin();
auto ys = y.begin();
long long ans = 1;
long long back_b = 1;
long long backed = 0;
while (x.end() != xs&&y.end() != ys) {
if (xs->first == ys->first) {
if (xs->first <= a) {
if (backed != ys->first - 1) {
back_b = 1;
}
long long hoge = back_b*back_b;
hoge %= MAX_MOD;
hoge *= xs->second;
hoge %= MAX_MOD;
ans += hoge;
ans %= MAX_MOD;
backed = ys->first;
back_b *= ys->second;
back_b++;
back_b %= MAX_MOD;
xs++;
ys++;
}
else break;
}
else if (xs->first < ys->first) {
if (xs->first <= a) {
if (backed != xs->first - 1) {
back_b = 1;
}
ans += xs->second;
ans %= MAX_MOD;
xs++;
}
else break;
}
else {
if (ys->first <= a) {
if (backed != ys->first - 1) {
back_b = 1;
}
backed = ys->first;
back_b *= ys->second;
back_b++;
back_b %= MAX_MOD;
ys++;
}
else break;
}
}
cout << ans%MAX_MOD << endl;
}
else if (s == "x") {
int a, b;
cin >> a >> b;
if (x_appear[a] == 0) {
x_appear[a] = 1;
x.insert(make_pair(a+1, b));
}
else {
for (auto i = x.begin();i != x.end();++i) {
int hoge = i -> first;
if (hoge == a+1) {
x.erase(i);
x.insert(make_pair(a+1, b));
break;
}
}
}
}
else {
//s == "y"
int a, b;
cin >> a >> b;
if (y_appear[a] == 0) {
y_appear[a] = 1;
y.insert(make_pair(a+1, b));
}
else {
for (auto i = y.begin();i != y.end();++i) {
int hoge = i->first;
if (hoge == a+1) {
y.erase(i);
y.insert(make_pair(a+1, b));
break;
}
}
}
}
}
}
kotamanegi