結果

問題 No.5010 Better Mo's Algorithm is Needed!! (Unweighted)
ユーザー norikamenorikame
提出日時 2022-12-17 20:32:03
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 5,000 ms
コード長 1,523 bytes
コンパイル時間 7,113 ms
実行使用メモリ 10,884 KB
スコア 16,092,896,139
最終ジャッジ日時 2022-12-17 20:38:49
合計ジャッジ時間 68,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 178 ms
10,800 KB
testcase_01 AC 177 ms
10,260 KB
testcase_02 AC 178 ms
10,476 KB
testcase_03 AC 179 ms
10,804 KB
testcase_04 AC 177 ms
10,524 KB
testcase_05 AC 176 ms
10,504 KB
testcase_06 AC 178 ms
10,812 KB
testcase_07 AC 177 ms
10,620 KB
testcase_08 AC 177 ms
10,592 KB
testcase_09 AC 178 ms
10,808 KB
testcase_10 AC 179 ms
10,480 KB
testcase_11 AC 179 ms
10,784 KB
testcase_12 AC 178 ms
10,796 KB
testcase_13 AC 177 ms
10,552 KB
testcase_14 AC 178 ms
10,556 KB
testcase_15 AC 179 ms
10,612 KB
testcase_16 AC 177 ms
10,480 KB
testcase_17 AC 176 ms
10,528 KB
testcase_18 AC 177 ms
10,740 KB
testcase_19 AC 176 ms
10,220 KB
testcase_20 AC 177 ms
10,532 KB
testcase_21 AC 177 ms
10,552 KB
testcase_22 AC 178 ms
10,216 KB
testcase_23 AC 176 ms
10,524 KB
testcase_24 AC 177 ms
10,792 KB
testcase_25 AC 177 ms
10,608 KB
testcase_26 AC 176 ms
10,536 KB
testcase_27 AC 180 ms
10,820 KB
testcase_28 AC 177 ms
10,520 KB
testcase_29 AC 177 ms
10,480 KB
testcase_30 AC 177 ms
10,820 KB
testcase_31 AC 177 ms
10,256 KB
testcase_32 AC 176 ms
10,556 KB
testcase_33 AC 178 ms
10,748 KB
testcase_34 AC 176 ms
10,620 KB
testcase_35 AC 177 ms
10,536 KB
testcase_36 AC 179 ms
10,748 KB
testcase_37 AC 177 ms
10,284 KB
testcase_38 AC 178 ms
10,552 KB
testcase_39 AC 177 ms
10,480 KB
testcase_40 AC 176 ms
10,268 KB
testcase_41 AC 178 ms
10,468 KB
testcase_42 AC 177 ms
10,744 KB
testcase_43 AC 177 ms
10,616 KB
testcase_44 AC 177 ms
10,568 KB
testcase_45 AC 177 ms
10,484 KB
testcase_46 AC 177 ms
10,484 KB
testcase_47 AC 176 ms
10,516 KB
testcase_48 AC 177 ms
10,476 KB
testcase_49 AC 176 ms
10,268 KB
testcase_50 AC 177 ms
10,544 KB
testcase_51 AC 177 ms
10,800 KB
testcase_52 AC 178 ms
10,480 KB
testcase_53 AC 177 ms
10,536 KB
testcase_54 AC 180 ms
10,744 KB
testcase_55 AC 177 ms
10,476 KB
testcase_56 AC 177 ms
10,484 KB
testcase_57 AC 178 ms
10,792 KB
testcase_58 AC 177 ms
10,532 KB
testcase_59 AC 177 ms
10,484 KB
testcase_60 AC 177 ms
10,752 KB
testcase_61 AC 177 ms
10,536 KB
testcase_62 AC 177 ms
10,880 KB
testcase_63 AC 177 ms
10,800 KB
testcase_64 AC 177 ms
10,280 KB
testcase_65 AC 180 ms
10,620 KB
testcase_66 AC 177 ms
10,748 KB
testcase_67 AC 177 ms
10,280 KB
testcase_68 AC 177 ms
10,516 KB
testcase_69 AC 178 ms
10,744 KB
testcase_70 AC 177 ms
10,572 KB
testcase_71 AC 176 ms
10,520 KB
testcase_72 AC 178 ms
10,480 KB
testcase_73 AC 177 ms
10,220 KB
testcase_74 AC 177 ms
10,520 KB
testcase_75 AC 177 ms
10,816 KB
testcase_76 AC 176 ms
10,484 KB
testcase_77 AC 176 ms
10,536 KB
testcase_78 AC 178 ms
10,780 KB
testcase_79 AC 177 ms
10,492 KB
testcase_80 AC 177 ms
10,532 KB
testcase_81 AC 177 ms
10,804 KB
testcase_82 AC 177 ms
10,604 KB
testcase_83 AC 177 ms
10,548 KB
testcase_84 AC 177 ms
10,744 KB
testcase_85 AC 176 ms
10,552 KB
testcase_86 AC 177 ms
10,564 KB
testcase_87 AC 178 ms
10,872 KB
testcase_88 AC 176 ms
10,296 KB
testcase_89 AC 180 ms
10,868 KB
testcase_90 AC 179 ms
10,748 KB
testcase_91 AC 177 ms
10,552 KB
testcase_92 AC 178 ms
10,588 KB
testcase_93 AC 177 ms
10,876 KB
testcase_94 AC 177 ms
10,528 KB
testcase_95 AC 176 ms
10,484 KB
testcase_96 AC 177 ms
10,792 KB
testcase_97 AC 177 ms
10,608 KB
testcase_98 AC 177 ms
10,520 KB
testcase_99 AC 179 ms
10,480 KB
testcase_100 AC 176 ms
10,484 KB
testcase_101 AC 177 ms
10,612 KB
testcase_102 AC 177 ms
10,748 KB
testcase_103 AC 178 ms
10,536 KB
testcase_104 AC 185 ms
10,548 KB
testcase_105 AC 183 ms
10,884 KB
testcase_106 AC 177 ms
10,284 KB
testcase_107 AC 177 ms
10,536 KB
testcase_108 AC 179 ms
10,800 KB
testcase_109 AC 178 ms
10,524 KB
testcase_110 AC 177 ms
10,524 KB
testcase_111 AC 176 ms
10,520 KB
testcase_112 AC 177 ms
10,552 KB
testcase_113 AC 178 ms
10,572 KB
testcase_114 AC 178 ms
10,484 KB
testcase_115 AC 178 ms
10,568 KB
testcase_116 AC 177 ms
10,616 KB
testcase_117 AC 178 ms
10,592 KB
testcase_118 AC 176 ms
10,264 KB
testcase_119 AC 177 ms
10,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const int INF = (int)(1e9);

int main() {
	int n, q, wt, st;
	cin >> n >> q >> wt >> st;
	vector<int> w(n), sum(n+1);
	rep(i, n) cin >> w[i];
	rep(i, n) sum[i+1] += sum[i] + w[i];
	vector<int> l(q), r(q);
	rep(i, q) cin >> l[i] >> r[i];
	int blen = (int)ceil(sqrt(q)), m = (n+1+blen-1) / blen;
	vector<vector<tuple<int, int, int>>> blst(m);
	rep(i, q) blst[l[i]/blen].emplace_back(r[i], l[i], i);
	int scnt = 0;
	rep(i, m) if (!blst[i].empty()) {
		if (scnt%2 == 0) sort(all(blst[i]));
		else sort(blst[i].rbegin(), blst[i].rend());
		++scnt;
	}
	vector<int> p(q);
	int pid = 0;
	rep(i, m) for (const auto& pi : blst[i]) {
		p[pid] = get<2>(pi);
		++pid;
	}
	int li = 0, ri = 0;
	bool fir = true;
	ll res = 0;
	rep(i, m) for (const auto& pi : blst[i]) {
		int nri = get<0>(pi), nli = get<1>(pi);
		if (fir) {
			res += sum[nri] - sum[nli-1];
			li = nli; ri = nri;
			fir = false;
		}
		else {
			int ai = min(li, nli), bi = max(li, nli), ci = min(ri, nri), di = max(ri, nri);
			res += (sum[bi-1]-sum[ai-1]) + (sum[di-1]-sum[ci-1]);
			li = nli; ri = nri;
		}
	}
	rep(i, q) cout << (p[i]+1) << (i<q-1?' ':'\n');
	return 0;
}
0