Submission #919739

# Submission time Handle Problem Language Result Execution time Memory
919739 2024-02-01T15:05:22 Z TIN Relativnost (COCI15_relativnost) C++17
0 / 140
2650 ms 50984 KB
#include <bits/stdc++.h>

using namespace std;

#define FNAME "test"

const int M = 10007;
const int N = 2e5 + 5;
const int C = 21;

int n, c, q;
int a[N], b[N];

struct Node {
	int chosen[C];

	Node() {
		for (int i = 0; i < C; i++) chosen[i] = 0;
	}

	Node operator + (const Node& oth) {
		Node nNode;
		for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= c; j++) {
				nNode.chosen[min(c, i + j)] = (1LL * nNode.chosen[min(c, i + j)] + 1LL * chosen[i] * oth.chosen[j]) % M;
			}
		}
		return nNode;
	}
} ST[3 * N];

void Task() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(9);
	if (fopen(FNAME".inp","r")) {
		freopen(FNAME".inp","r",stdin);
		freopen(FNAME".out","w",stdout);
	}
}

void build(int id, int l, int r) {
	if (l == r) {
		ST[id].chosen[0] = b[l] % M;
		ST[id].chosen[1] = a[r] % M;
		return;
	}
	int m = (l + r) / 2;
	build(id * 2, l, m);
	build(id * 2 + 1, m + 1, r);
	ST[id] = ST[id * 2] + ST[id * 2 + 1];
}

void update(int id, int l, int r, int pos, int vala, int valb) {
	if (pos < l || r < pos) return;
	if (l == r) {
		a[pos] = vala; ST[id].chosen[1] = a[pos] % M;
		b[pos] = valb; ST[id].chosen[0] = b[pos] % M;
		return;
	}
	int m = (l + r) / 2;
	if (pos <= m) update(id * 2, l, m, pos, vala, valb);
	else update(id * 2 + 1, m + 1, r, pos, vala, valb);
	ST[id] = ST[id * 2] + ST[id * 2 + 1];
}

void Solve() {
	//Your Code
	cin >> n >> c;
	for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	build(1, 1, n);
	cin >> q;
	while (q--) {
		int pos;
		int vala, valb;
		cin >> pos >> vala >> valb;
		update(1, 1, n, pos, vala, valb);
		cout << ST[1].chosen[c] << '\n';
	}
}

int main() {
	Task();
	Solve();
	cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms";
	return 37^37;
}

Compilation message

relativnost.cpp: In function 'void Task()':
relativnost.cpp:37:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   freopen(FNAME".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
relativnost.cpp:38:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   freopen(FNAME".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 49752 KB Memory limit exceeded
2 Runtime error 17 ms 49752 KB Memory limit exceeded
3 Runtime error 26 ms 49764 KB Memory limit exceeded
4 Runtime error 320 ms 50260 KB Memory limit exceeded
5 Runtime error 1103 ms 50768 KB Memory limit exceeded
6 Runtime error 1658 ms 50984 KB Memory limit exceeded
7 Runtime error 697 ms 50500 KB Memory limit exceeded
8 Runtime error 372 ms 50480 KB Memory limit exceeded
9 Runtime error 674 ms 50476 KB Memory limit exceeded
10 Runtime error 2650 ms 50784 KB Memory limit exceeded