Submission #1339254

#TimeUsernameProblemLanguageResultExecution timeMemory
1339254becastalRegions (IOI09_regions)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
using namespace std;

const int MAXR = 25010;
ll Res[MAXR][MAXR];

struct Bit {
	int n;
	vector<int> F;

	Bit(int n_) : n(n_), F(n+1) {};
	void update(int i, int x) {
		for (i++; i <= n; i+=i&-i) {
			F[i] += x;
		}
	}

	int pref(int i) {
		int res = 0;
		for (i++; i; i-=i&-i) {
			res += F[i];
		}
		return res;
	}
};

int solve() {
	int n, r, q; cin >> n >> r >> q;
	vector<int> Pai(n, -1), Cor(n);
	vector<vector<int>> G(n), Ocor(r);

	for (int i = 0; i < n; i++) {
		if (i) {
			cin >> Pai[i]; Pai[i]--;
			cin >> Cor[i]; Cor[i]--;
			G[Pai[i]].push_back(i);
		} else {
			cin >> Cor[i]; Cor[i]--;
		}
		Ocor[Cor[i]].push_back(i);
	}

	int t = 0;
	vector<int> L(n), R(n);
	function<void(int)> dfs = [&](int u) {
		L[u] = t++;
		for (int v : G[u]) {
			dfs(v);
		}
		R[u] = t;
	};
	dfs(0);

	Bit bit(n);
	for (int r1 = 0; r1 < r; r1++) {
		for (int u : Ocor[r1]) {
			bit.update(L[u], +1);
			bit.update(R[u], -1);
		}
		
		for (int r2 = 0; r2 < r; r2++) {
			for (int u : Ocor[r2]) {
				Res[r1][r2] += bit.pref(L[u]);
			}
		}

		for (int u : Ocor[r1]) {
			bit.update(L[u], -1);
			bit.update(R[u], +1);
		}
	}

	for (int i = 0, r1, r2; i < q; i++) {
		cin >> r1 >> r2; r1--, r2--;
		cout << Res[r1][r2] << endl;
		cout << flush;
	}

	return(0);
}

signed main()
{
    //_;

	int t = 1; //cin >> t;
	while (t--) {
		solve();
	}
    
    return(0);
}

Compilation message (stderr)

/tmp/ccMmVt9c.o: in function `solve()':
regions.cpp:(.text+0x179): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
regions.cpp:(.text+0x406): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
regions.cpp:(.text+0x463): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
regions.cpp:(.text+0x473): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
regions.cpp:(.text+0xbc9): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
regions.cpp:(.text+0xc17): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
/usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(vterminate.o): in function `__gnu_cxx::__verbose_terminate_handler()':
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x22): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x2f): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
/usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(ios_init.o): in function `std::ios_base::Init::Init()':
(.text._ZNSt8ios_base4InitC2Ev+0x1f): failed to convert GOTPCREL relocation against '_ZNSt8ios_base4Init11_S_refcountE'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5f): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x66): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x71): additional relocation overflows omitted from the output
(.text._ZNSt8ios_base4InitC2Ev+0x1ed): failed to convert GOTPCREL relocation against '_ZSt4cout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x252): failed to convert GOTPCREL relocation against '_ZSt3cin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x2bc): failed to convert GOTPCREL relocation against '_ZSt4cerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x316): failed to convert GOTPCREL relocation against '_ZSt4clog'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x50f): failed to convert GOTPCREL relocation against '_ZSt5wcout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x57d): failed to convert GOTPCREL relocation against '_ZSt4wcin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5f0): failed to convert GOTPCREL relocation against '_ZSt5wcerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x654): failed to convert GOTPCREL relocation against '_ZSt5wclog'; relink with --no-relax
/usr/bin/ld: final link failed
collect2: error: ld returned 1 exit status