結果

問題 No.1441 MErGe
ユーザー uzzy
提出日時 2021-03-27 01:02:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 438 ms / 1,000 ms
コード長 1,753 bytes
コンパイル時間 2,708 ms
コンパイル使用メモリ 193,424 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-11-29 04:15:26
合計ジャッジ時間 11,639 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int bm = 200201;
int BIT[bm];
void add(int A, int B) {
	if (A == 0) return;
	while (A <= bm) {
		BIT[A] += B;
		A += A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A > 0) {
		ret += BIT[A];
		A -= A & -A;
	}
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, Q;
	cin >> N >> Q;
	int A[200200];
	ll S[200200] = {};
	rep1(i, N) cin >> A[i];
	rep(i, N) S[i + 1] = S[i] + A[i + 1];

	rep1(i, N) {
		add(i, 1);
	}

	set<int> ST;
	rep1(i, N) ST.insert(i);

	int kazu = N;
	rep(q, Q) {
		int t, l, r;
		cin >> t >> l >> r;

		int L, R;
		int k1 = 0, k2 = N + 1;
		while (k1 + 1 < k2) {
			int k = (k1 + k2) / 2;
			int tmp = query(k);
			if (tmp >= l) k2 = k;
			else k1 = k;
		}
		L = k2;
		k1 = 0;
		k2 = N + 1;
		while (k1 + 1 < k2) {
			int k = (k1 + k2) / 2;
			int tmp = query(k);
			if (tmp > r) k2 = k;
			else k1 = k;
		}
		R = k2;
		

		if (t == 1) {
			auto itr1 = ST.lower_bound(L);
			auto itr2 = ST.lower_bound(R);
			vector<int> are;
			itr1++;
			while (itr1 != itr2) {
				add(*itr1, -1);
				are.pb(*itr1);
				itr1++;
			}
			for (auto t : are) ST.erase(t);
		}
		else {
			co(S[R - 1] - S[L - 1]);
		}
	}

	Would you please return 0;
}
0