結果

問題 No.510 二次漸化式
ユーザー pekempeypekempey
提出日時 2017-04-30 18:52:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,188 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 74,280 KB
実行使用メモリ 12,168 KB
最終ジャッジ日時 2023-10-11 23:55:24
合計ジャッジ時間 3,749 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 9 ms
4,372 KB
testcase_07 AC 9 ms
4,368 KB
testcase_08 WA -
testcase_09 AC 9 ms
4,368 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 11 ms
12,064 KB
testcase_17 AC 11 ms
11,944 KB
testcase_18 AC 11 ms
12,004 KB
testcase_19 AC 11 ms
11,952 KB
testcase_20 AC 10 ms
11,952 KB
testcase_21 AC 11 ms
12,016 KB
testcase_22 AC 11 ms
12,128 KB
testcase_23 AC 16 ms
12,008 KB
testcase_24 AC 16 ms
11,912 KB
testcase_25 AC 16 ms
12,060 KB
testcase_26 AC 16 ms
11,952 KB
testcase_27 AC 16 ms
12,072 KB
testcase_28 AC 16 ms
11,952 KB
testcase_29 AC 16 ms
11,996 KB
testcase_30 AC 16 ms
12,168 KB
testcase_31 AC 17 ms
11,912 KB
testcase_32 AC 19 ms
12,124 KB
testcase_33 AC 19 ms
11,968 KB
testcase_34 AC 13 ms
11,948 KB
testcase_35 AC 9 ms
11,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <array>
#include <vector>

const int mod = 1e9 + 7;

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

char readChar() {
	int c;
	while ((c = getchar()) < 'a');
	return c;
}

int readInt() {
	int n, c;
	while ((c = getchar()) < '0');
	n = c - '0';
	while ((c = getchar()) >= '0') {
		n = n * 10 + c - '0';
	}
	return n;
}

void writeInt(int n) {
	int d[11];
	int i = 0;
	do {
		d[i++] = n % 10;
		n /= 10;
	} while (n > 0);
	while (i > 0) {
		putchar(d[--i] + '0');
	}
	putchar('\n');
}

// stupid...
struct foo {
	int a, b, c, d, e, f, g, h;
};

foo operator*(const foo &x, const foo &y) {
	foo ret;
	ret.a = (y.a + 1LL * x.a * y.d + 1LL * x.b * y.f) % mod;
	ret.b = (y.b + 1LL * x.b * y.g) % mod;
	ret.c = (x.c + y.c + 1LL * x.a * y.e + 1LL * x.b * y.h) % mod;
	ret.d = 1LL * x.d * y.d % mod;
	ret.e = (x.e + 1LL * x.d * y.e) % mod;
	ret.f = (1LL * y.d * x.f + 1LL * y.f * x.g) % mod;
	ret.g = 1LL * x.g * y.g % mod;
	ret.h = (1LL * y.e * x.f + x.h + 1LL * x.g * y.h) % mod;
	return ret;
}

foo getmat(long long x, long long y) {
	foo c;
	c.a = 0;
	c.b = x;
	c.c = 0;
	c.d = y;
	c.e = 1;
	c.f = 2 * y % mod;
	c.g = y * y % mod;
	c.h = 1;
	return c;
}

int main() {
	int n = readInt();
	int q = readInt();

	std::vector<int> xs(n);
	std::vector<int> ys(n);

	int N = 1;
	while (N < n) {
		N *= 2;
	}
	std::vector<foo> seg(N * 2, getmat(0, 0));

	auto setval = [&](int k, foo v) {
		k += N;
		seg[k] = v;
		while (k > 1) {
			k /= 2;
			seg[k] = seg[k * 2 + 1] * seg[k * 2];
		}
	};

	auto getval = [&](int k) {
		if (k == N) {
			return seg[1];
		}
		k += N;
		foo ret = {};
		ret.d = 1;
		ret.g = 1;
		while (k > 1) {
			if (k & 1) {
				ret = ret * seg[k - 1];
			}
			k /= 2;
		}
		return ret;
	};

	while (q--) {
		char c = readChar();
		if (c == 'x') {
			int i = readInt();
			int v = readInt();
			xs[i] = v;
			setval(i, getmat(xs[i], ys[i]));
		} else if (c == 'y') {
			int i = readInt();
			int v = readInt();
			ys[i] = v;
			setval(i, getmat(xs[i], ys[i]));
		} else {
			int i = readInt();
			auto m = getval(i);
			writeInt((m.a + m.b + m.c + 1) % mod);
		}
	}
}
0