提出 #68960395


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

int main() {
	int q;
	cin >> q;
	int n = q + 1;
	vector<pair<int, int>> queries(q);
	for (int i = 0; i < q; i++) {
		int type, x;
		cin >> type >> x;
		if (type == 1) {
			queries[i] = {x, -1};
		} else {
			int y;
			cin >> y;
			queries[i] = {x, y};
		}
	}
	
	vector<vector<int>> next(n);
	for (int i = 1; i <= q; i++) {
		auto [x, y] = queries[i - 1];
		if (y == -1) next[x].push_back(i);
	}
	vector<int> b;
	stack<int> st;
	st.push(0);
	while (!st.empty()) {
		int x = st.top(); st.pop();
		b.push_back(x);
		for (auto y : next[x]) st.push(y);
	}
	
	vector<int> p(n);
	for (int i = 0; i < b.size(); i++) p[b[i]] = i;
	vector<int> v(n);
	set<int> non_zero;
	for (int i = 1; i <= q; i++) {
		auto [x, y] = queries[i - 1];
		if (y == -1) {
			v[p[i]] = i;
			non_zero.insert(p[i]);
		} else {
			int l = p[x], r = p[y];
			if (l > r) swap(l, r);
			long long sum = 0;
			while (l < r) {
				auto it = non_zero.upper_bound(l);
				if (it == non_zero.end()) break;
				int z = *it;
				if (z >= r) break;
				non_zero.erase(it);
				sum += v[z];
				v[z] = 0;
				l = z;
			}
			cout << sum << "\n";
		}
	}
}

提出情報

提出日時
問題 F - Erase between X and Y
ユーザ KumaTachiRen
言語 C++ 20 (gcc 12.2)
得点 525
コード長 1214 Byte
結果 AC
実行時間 335 ms
メモリ 63684 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:36:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   36 |         for (int i = 0; i < b.size(); i++) p[b[i]] = i;
      |                         ~~^~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 525 / 525
結果
AC × 3
AC × 36
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 2 ms 3464 KiB
00_sample_01.txt AC 1 ms 3628 KiB
00_sample_02.txt AC 1 ms 3544 KiB
01_random_00.txt AC 159 ms 22636 KiB
01_random_01.txt AC 203 ms 23476 KiB
01_random_02.txt AC 203 ms 24108 KiB
01_random_03.txt AC 205 ms 24328 KiB
01_random_04.txt AC 207 ms 25156 KiB
01_random_05.txt AC 208 ms 25488 KiB
01_random_06.txt AC 208 ms 26280 KiB
01_random_07.txt AC 209 ms 26712 KiB
01_random_08.txt AC 210 ms 27188 KiB
01_random_09.txt AC 213 ms 27940 KiB
01_random_10.txt AC 214 ms 28164 KiB
01_random_11.txt AC 212 ms 28940 KiB
01_random_12.txt AC 212 ms 29456 KiB
01_random_13.txt AC 213 ms 29800 KiB
01_random_14.txt AC 212 ms 30328 KiB
01_random_15.txt AC 211 ms 30700 KiB
01_random_16.txt AC 210 ms 30968 KiB
01_random_17.txt AC 210 ms 31536 KiB
01_random_18.txt AC 210 ms 31848 KiB
01_random_19.txt AC 211 ms 32232 KiB
01_random_20.txt AC 335 ms 56088 KiB
02_random2_00.txt AC 236 ms 42392 KiB
02_random2_01.txt AC 238 ms 43476 KiB
02_random2_02.txt AC 227 ms 44308 KiB
02_random2_03.txt AC 220 ms 49896 KiB
02_random2_04.txt AC 213 ms 53480 KiB
03_handmade_00.txt AC 1 ms 3528 KiB
03_handmade_01.txt AC 250 ms 63664 KiB
03_handmade_02.txt AC 196 ms 50164 KiB
03_handmade_03.txt AC 269 ms 63684 KiB
03_handmade_04.txt AC 247 ms 43196 KiB
03_handmade_05.txt AC 219 ms 36296 KiB
03_handmade_06.txt AC 211 ms 39816 KiB