提出 #68960371


ソースコード 拡げる

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

#include <atcoder/lazysegtree>
using ll = long long;
ll op(ll x, ll y) { return x + y; }
ll e() { return 0; }
ll mapping(bool f, ll x) { return f ? 0 : x; }
bool id() { return false; }
bool composition(bool f, bool g) { return f or g; }
using lazyseg = atcoder::lazy_segtree<ll, op, e, bool, mapping, composition, id>;

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;
	lazyseg seg(n);
	for (int i = 1; i <= q; i++) {
		auto [x, y] = queries[i - 1];
		if (y == -1) {
			seg.set(p[i], i);
		} else {
			int l = p[x], r = p[y];
			if (l > r) swap(l, r);
			l++;
			ll sum = seg.prod(l, r);
			seg.apply(l, r, true);
			cout << sum << "\n";
		}
	}
}

提出情報

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

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:45:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   45 |         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 3492 KiB
00_sample_01.txt AC 1 ms 3464 KiB
00_sample_02.txt AC 1 ms 3472 KiB
01_random_00.txt AC 167 ms 32948 KiB
01_random_01.txt AC 539 ms 33524 KiB
01_random_02.txt AC 525 ms 34152 KiB
01_random_03.txt AC 510 ms 34644 KiB
01_random_04.txt AC 500 ms 35076 KiB
01_random_05.txt AC 484 ms 35792 KiB
01_random_06.txt AC 469 ms 36224 KiB
01_random_07.txt AC 453 ms 36884 KiB
01_random_08.txt AC 437 ms 37536 KiB
01_random_09.txt AC 425 ms 37944 KiB
01_random_10.txt AC 409 ms 38472 KiB
01_random_11.txt AC 397 ms 38988 KiB
01_random_12.txt AC 380 ms 39324 KiB
01_random_13.txt AC 367 ms 39824 KiB
01_random_14.txt AC 347 ms 40376 KiB
01_random_15.txt AC 330 ms 40628 KiB
01_random_16.txt AC 315 ms 41240 KiB
01_random_17.txt AC 302 ms 41764 KiB
01_random_18.txt AC 280 ms 42216 KiB
01_random_19.txt AC 264 ms 42612 KiB
01_random_20.txt AC 281 ms 42900 KiB
02_random2_00.txt AC 310 ms 41708 KiB
02_random2_01.txt AC 271 ms 43068 KiB
02_random2_02.txt AC 255 ms 43836 KiB
02_random2_03.txt AC 237 ms 44144 KiB
02_random2_04.txt AC 230 ms 44400 KiB
03_handmade_00.txt AC 1 ms 3548 KiB
03_handmade_01.txt AC 239 ms 50500 KiB
03_handmade_02.txt AC 185 ms 38832 KiB
03_handmade_03.txt AC 239 ms 50488 KiB
03_handmade_04.txt AC 245 ms 41792 KiB
03_handmade_05.txt AC 220 ms 36124 KiB
03_handmade_06.txt AC 215 ms 38900 KiB