結果

問題 No.510 二次漸化式
ユーザー kotamanegikotamanegi
提出日時 2017-04-28 23:43:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,571 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 98,672 KB
実行使用メモリ 5,496 KB
最終ジャッジ日時 2023-10-11 19:50:27
合計ジャッジ時間 12,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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<int, int> x_appear;
map<int, int> y_appear;
int main() {
#define int long long
	long long n, query;
	cin >> n >> query;
	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) {
						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;
					}
				}
			}
		}
	}
}
0