提出 #68960972


ソースコード 拡げる

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

#include <atcoder/segtree>
bool op(bool x, bool y) { return x or y; }
bool e() { return false; }
bool f(bool v) { return !v; }

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;
	atcoder::segtree<bool, op, e> seg(b.size());
	for (int i = 1; i <= q; i++) {
		auto [x, y] = queries[i - 1];
		if (y == -1) {
			seg.set(p[i], true);
		} else {
			int l = p[x], r = p[y];
			if (l > r) swap(l, r);
			long long sum = 0;
			while (l < r) {
				int z = seg.max_right<f>(l + 1);
				if (z >= r) break;
				seg.set(z, false);
				sum += b[z];
				l = z;
			}
			cout << sum << "\n";
		}
	}
}

提出情報

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

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:41:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   41 |         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 1 ms 3560 KiB
00_sample_01.txt AC 1 ms 3492 KiB
00_sample_02.txt AC 1 ms 3584 KiB
01_random_00.txt AC 160 ms 20812 KiB
01_random_01.txt AC 242 ms 21336 KiB
01_random_02.txt AC 248 ms 21956 KiB
01_random_03.txt AC 254 ms 22568 KiB
01_random_04.txt AC 256 ms 23064 KiB
01_random_05.txt AC 262 ms 23768 KiB
01_random_06.txt AC 270 ms 24188 KiB
01_random_07.txt AC 265 ms 25032 KiB
01_random_08.txt AC 267 ms 25448 KiB
01_random_09.txt AC 268 ms 25776 KiB
01_random_10.txt AC 268 ms 26404 KiB
01_random_11.txt AC 272 ms 26900 KiB
01_random_12.txt AC 272 ms 27220 KiB
01_random_13.txt AC 270 ms 27812 KiB
01_random_14.txt AC 269 ms 28300 KiB
01_random_15.txt AC 269 ms 28876 KiB
01_random_16.txt AC 264 ms 29232 KiB
01_random_17.txt AC 263 ms 29432 KiB
01_random_18.txt AC 262 ms 30296 KiB
01_random_19.txt AC 259 ms 30420 KiB
01_random_20.txt AC 231 ms 31020 KiB
02_random2_00.txt AC 242 ms 29836 KiB
02_random2_01.txt AC 227 ms 30732 KiB
02_random2_02.txt AC 210 ms 31592 KiB
02_random2_03.txt AC 194 ms 32040 KiB
02_random2_04.txt AC 186 ms 32272 KiB
03_handmade_00.txt AC 1 ms 3504 KiB
03_handmade_01.txt AC 201 ms 38624 KiB
03_handmade_02.txt AC 146 ms 26648 KiB
03_handmade_03.txt AC 249 ms 38632 KiB
03_handmade_04.txt AC 222 ms 29944 KiB
03_handmade_05.txt AC 197 ms 23964 KiB
03_handmade_06.txt AC 190 ms 27048 KiB