結果

問題 No.1441 MErGe
ユーザー XDXD
提出日時 2021-11-12 11:50:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 1,000 ms
コード長 3,149 bytes
コンパイル時間 2,574 ms
コンパイル使用メモリ 165,644 KB
実行使用メモリ 17,912 KB
最終ジャッジ日時 2023-08-16 09:06:45
合計ジャッジ時間 6,246 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,492 KB
testcase_01 AC 2 ms
7,448 KB
testcase_02 AC 2 ms
7,496 KB
testcase_03 AC 3 ms
7,544 KB
testcase_04 AC 3 ms
7,480 KB
testcase_05 AC 4 ms
7,572 KB
testcase_06 AC 5 ms
7,748 KB
testcase_07 AC 4 ms
7,528 KB
testcase_08 AC 25 ms
12,092 KB
testcase_09 AC 24 ms
12,300 KB
testcase_10 AC 37 ms
12,120 KB
testcase_11 AC 36 ms
11,968 KB
testcase_12 AC 38 ms
12,184 KB
testcase_13 AC 72 ms
15,584 KB
testcase_14 AC 74 ms
15,588 KB
testcase_15 AC 77 ms
15,584 KB
testcase_16 AC 69 ms
15,576 KB
testcase_17 AC 71 ms
15,552 KB
testcase_18 AC 70 ms
15,480 KB
testcase_19 AC 79 ms
15,548 KB
testcase_20 AC 61 ms
15,156 KB
testcase_21 AC 54 ms
14,924 KB
testcase_22 AC 80 ms
16,860 KB
testcase_23 AC 96 ms
17,664 KB
testcase_24 AC 95 ms
17,836 KB
testcase_25 AC 94 ms
17,912 KB
testcase_26 AC 91 ms
17,736 KB
testcase_27 AC 95 ms
17,676 KB
testcase_28 AC 38 ms
15,684 KB
testcase_29 AC 38 ms
15,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s); i<=(t); ++i)
#define forl(i,s,t) for(register i64 i=(s); i<=(t); ++i)
#define form(i,s,t) for(register int i=(s); i>=(t); --i)
#define rep(i,s,t) for(register int i=(s); i<(t); ++i)
#define IT(u) for(register int i=G[u]; i; i=E[i].nxt)
using namespace std;
namespace FASTIO {
	const int SIZ = 1 << 26 | 1;
	char ibuf[SIZ], obuf[SIZ], *iS = ibuf, *iT = ibuf, *oS = obuf, *oT = obuf + SIZ - 1, qwq[60], qaq;
	#define gc() (iS == iT && (iT = (iS = ibuf) + fread(ibuf, 1, SIZ, stdin), iS == iT) ? EOF : *iS++)
	template<typename T>
	inline void Rdn(T& A) {
		register bool fl = 0;
		register char ch = gc(); A = 0;
		while(!isdigit(ch)) fl = (ch == '-'), ch = gc();
		while(isdigit(ch)) A = (A * 10) + (ch & 15), ch = gc();
		fl && (A = -A);
	}
	inline void Rdn(char& c) {while((c = gc()) == ' ' || c == '\n' || c == '\r');}
	inline void Rdn(char* s) {
		while((*s = gc()) == ' ' || *s == '\n' || *s == '\r') ;
		if(*s == EOF) return ;
		while(*s != ' ' && *s != '\n' && *s != '\r' && *s != EOF) *(++s) = gc();
		*s = 0;
	}
	template<typename T, typename ...U>
	inline void Rdn(T& A, U& ...B) {Rdn(A), Rdn(B...);}
	inline void flush() {fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;}
	inline void pc(char c) {*oS ++ = c; if(oS == oT) flush();}
	template<typename T>
	inline void Wtn(T A) {
		if(!A) return pc('0'); if(A < 0) pc('-'), A = -A;
		while(A) qwq[++qaq] = A % 10 + '0', A /= 10;
		while(qaq) pc(qwq[qaq -- ]);
	}
	inline void Wtn(char A) {pc(A);}
	inline void Wtn(char *s) {while(*s) pc(*s), ++s;}
	inline void Wtn(const char *s) {while(*s) pc(*s), ++s;}
	template<typename T, typename ...U>
	inline void Wtn(T A, U ...B) {Wtn(A), Wtn(B...);}
#undef gc
}
using FASTIO :: Rdn;
using FASTIO :: Wtn;
using FASTIO :: flush;
typedef long long i64;
typedef double f64;
typedef unsigned long long u64;
typedef pair<i64, i64> pii;
typedef pair<int, u64> piu;
const int N = 2e5 + 5;
const i64 INF = 1e18;
inline void init() {}
int n, m, nxt[N], pre[N]; i64 a[N];
struct BIT {
	int val[N], R, A;
	inline void upd(int p, int k) {while (p <= R) val[p] += k, p += p & -p; }
	inline int Qry(int p) {A = 0; while (p) A += val[p], p -= p & -p; return A; }
	inline int qry(int p) {
		int res = 0;
		form (i, 19, 0) if (res + (1 << i) <= R && p >= val[res | 1 << i]) res ^= 1 << i, p -= val[res];
		return res;
	}
} ZT;
inline void solve() {
	Rdn(n, m); ZT.R = n;
	forn (i, 1, n) Rdn(a[i]), a[i] += a[i - 1], ZT.upd(i, 1), nxt[i] = i + 1, pre[i] = i - 1;
	forn (i, 1, m) {
		int opt, l, r, lim; Rdn(opt, l, r); lim = r - l;
		if (opt == 1) {
			int nowp = ZT.qry(l - 1) + 1;
			while (lim -- ) /*Wtn(nowp, '\n'), */ZT.upd(nowp, -1), pre[nxt[nowp]] = pre[nowp], nxt[pre[nowp]] = nxt[nowp], nowp = nxt[nowp];
		} else {
//			Wtn(ZT.qry(l), ' ', ZT.qry(r + 1), '\n');
			Wtn(a[ZT.qry(r - 1) + 1] - (l == 1 ? 0 : a[ZT.qry(l - 2) + 1]), '\n');
		}
//		forn (i, 0, 17) Wtn(ZT.val[1 << i], " \n"[i == 17]);
//		forn (j, 1, n) Wtn(ZT.Qry(j), " \n"[j == n]); 
//		forn (j, 1, n) Wtn(ZT.qry(j), " \n"[j == n]);
	} 
}
int Trd;
int main() {
	Trd = 1;
	while(Trd--) init(), solve(); flush();
	return 0;
}
0