結果

問題 No.5011 Better Mo's Algorithm is Needed!! (Weighted)
ユーザー norikamenorikame
提出日時 2022-12-17 20:43:30
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 5,000 ms
コード長 1,523 bytes
コンパイル時間 6,735 ms
実行使用メモリ 10,868 KB
スコア 34,918,033,327
最終ジャッジ日時 2022-12-17 20:44:40
合計ジャッジ時間 69,990 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
10,788 KB
testcase_01 AC 171 ms
10,620 KB
testcase_02 AC 173 ms
10,540 KB
testcase_03 AC 172 ms
10,540 KB
testcase_04 AC 174 ms
10,528 KB
testcase_05 AC 173 ms
10,476 KB
testcase_06 AC 172 ms
10,800 KB
testcase_07 AC 172 ms
10,244 KB
testcase_08 AC 171 ms
10,596 KB
testcase_09 AC 173 ms
10,516 KB
testcase_10 AC 173 ms
10,580 KB
testcase_11 AC 174 ms
10,568 KB
testcase_12 AC 173 ms
10,484 KB
testcase_13 AC 172 ms
10,480 KB
testcase_14 AC 171 ms
10,540 KB
testcase_15 AC 174 ms
10,792 KB
testcase_16 AC 173 ms
10,480 KB
testcase_17 AC 172 ms
10,476 KB
testcase_18 AC 171 ms
10,868 KB
testcase_19 AC 171 ms
10,548 KB
testcase_20 AC 172 ms
10,624 KB
testcase_21 AC 174 ms
10,796 KB
testcase_22 AC 173 ms
10,476 KB
testcase_23 AC 172 ms
10,540 KB
testcase_24 AC 172 ms
10,816 KB
testcase_25 AC 171 ms
10,524 KB
testcase_26 AC 171 ms
10,576 KB
testcase_27 AC 172 ms
10,480 KB
testcase_28 AC 172 ms
10,208 KB
testcase_29 AC 172 ms
10,504 KB
testcase_30 AC 171 ms
10,740 KB
testcase_31 AC 171 ms
10,616 KB
testcase_32 AC 170 ms
10,516 KB
testcase_33 AC 173 ms
10,788 KB
testcase_34 AC 171 ms
10,564 KB
testcase_35 AC 172 ms
10,472 KB
testcase_36 AC 172 ms
10,804 KB
testcase_37 AC 172 ms
10,240 KB
testcase_38 AC 172 ms
10,536 KB
testcase_39 AC 174 ms
10,796 KB
testcase_40 AC 172 ms
10,244 KB
testcase_41 AC 171 ms
10,548 KB
testcase_42 AC 172 ms
10,740 KB
testcase_43 AC 190 ms
10,544 KB
testcase_44 AC 171 ms
10,596 KB
testcase_45 AC 172 ms
10,620 KB
testcase_46 AC 174 ms
10,528 KB
testcase_47 AC 173 ms
10,520 KB
testcase_48 AC 173 ms
10,788 KB
testcase_49 AC 172 ms
10,592 KB
testcase_50 AC 172 ms
10,480 KB
testcase_51 AC 174 ms
10,864 KB
testcase_52 AC 174 ms
10,484 KB
testcase_53 AC 172 ms
10,540 KB
testcase_54 AC 173 ms
10,736 KB
testcase_55 AC 170 ms
10,476 KB
testcase_56 AC 170 ms
10,524 KB
testcase_57 AC 173 ms
10,740 KB
testcase_58 AC 173 ms
10,212 KB
testcase_59 AC 173 ms
10,536 KB
testcase_60 AC 173 ms
10,576 KB
testcase_61 AC 170 ms
10,552 KB
testcase_62 AC 174 ms
10,536 KB
testcase_63 AC 172 ms
10,476 KB
testcase_64 AC 173 ms
10,528 KB
testcase_65 AC 172 ms
10,536 KB
testcase_66 AC 171 ms
10,868 KB
testcase_67 AC 170 ms
10,520 KB
testcase_68 AC 171 ms
10,484 KB
testcase_69 AC 173 ms
10,740 KB
testcase_70 AC 175 ms
10,472 KB
testcase_71 AC 173 ms
10,544 KB
testcase_72 AC 172 ms
10,508 KB
testcase_73 AC 171 ms
10,544 KB
testcase_74 AC 173 ms
10,476 KB
testcase_75 AC 173 ms
10,476 KB
testcase_76 AC 171 ms
10,504 KB
testcase_77 AC 172 ms
10,476 KB
testcase_78 AC 171 ms
10,520 KB
testcase_79 AC 171 ms
10,548 KB
testcase_80 AC 171 ms
10,548 KB
testcase_81 AC 173 ms
10,804 KB
testcase_82 AC 172 ms
10,604 KB
testcase_83 AC 172 ms
10,552 KB
testcase_84 AC 172 ms
10,780 KB
testcase_85 AC 172 ms
10,480 KB
testcase_86 AC 170 ms
10,524 KB
testcase_87 AC 172 ms
10,856 KB
testcase_88 AC 171 ms
10,260 KB
testcase_89 AC 172 ms
10,616 KB
testcase_90 AC 170 ms
10,816 KB
testcase_91 AC 171 ms
10,356 KB
testcase_92 AC 172 ms
10,476 KB
testcase_93 AC 174 ms
10,812 KB
testcase_94 AC 174 ms
10,532 KB
testcase_95 AC 173 ms
10,520 KB
testcase_96 AC 173 ms
10,540 KB
testcase_97 AC 173 ms
10,528 KB
testcase_98 AC 173 ms
10,520 KB
testcase_99 AC 174 ms
10,796 KB
testcase_100 AC 173 ms
10,340 KB
testcase_101 AC 172 ms
10,524 KB
testcase_102 AC 171 ms
10,476 KB
testcase_103 AC 171 ms
10,476 KB
testcase_104 AC 172 ms
10,584 KB
testcase_105 AC 173 ms
10,744 KB
testcase_106 AC 172 ms
10,548 KB
testcase_107 AC 173 ms
10,516 KB
testcase_108 AC 171 ms
10,532 KB
testcase_109 AC 172 ms
10,592 KB
testcase_110 AC 172 ms
10,612 KB
testcase_111 AC 174 ms
10,856 KB
testcase_112 AC 171 ms
10,480 KB
testcase_113 AC 172 ms
10,524 KB
testcase_114 AC 172 ms
10,752 KB
testcase_115 AC 171 ms
10,484 KB
testcase_116 AC 171 ms
10,472 KB
testcase_117 AC 173 ms
10,504 KB
testcase_118 AC 172 ms
10,220 KB
testcase_119 AC 173 ms
10,536 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