QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876408#9974. After godzltWA 2401ms468788kbC++146.7kb2025-01-30 20:54:092025-01-30 20:54:10

Judging History

This is the latest submission verdict.

  • [2025-01-30 20:54:10]
  • Judged
  • Verdict: WA
  • Time: 2401ms
  • Memory: 468788kb
  • [2025-01-30 20:54:09]
  • Submitted

answer

// Problem: P11368 [Ynoi2024] After god
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P11368
// Memory Limit: 512 MB
// Time Limit: 2500 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define uint unsigned
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<int, int> pii;

namespace IO {
	const int maxn = 1 << 20;
	
    char ibuf[maxn], *iS, *iT, obuf[maxn], *oS = obuf;

	inline char gc() {
		return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++) : *iS++);
	}

	template<typename T = int>
	inline T read() {
		char c = gc();
		T x = 0;
		bool f = 0;
		while (c < '0' || c > '9') {
			f |= (c == '-');
			c = gc();
		}
		while (c >= '0' && c <= '9') {
			x = (x << 1) + (x << 3) + (c ^ 48);
			c = gc();
		}
		return f ? ~(x - 1) : x;
	}

	inline void flush() {
		fwrite(obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	
	struct Flusher {
		~Flusher() {
			flush();
		}
	} AutoFlush;

	inline void pc(char ch) {
		if (oS == obuf + maxn) {
			flush();
		}
		*oS++ = ch;
	}

	template<typename T>
	inline void write(T x) {
		static char stk[64], *tp = stk;
		if (x < 0) {
			x = ~(x - 1);
			pc('-');
		}
		do {
			*tp++ = x % 10;
			x /= 10;
		} while (x);
		while (tp != stk) {
			pc((*--tp) | 48);
		}
	}
	
	template<typename T>
	inline void writesp(T x) {
		write(x);
		pc(' ');
	}
	
	template<typename T>
	inline void writeln(T x) {
		write(x);
		pc('\n');
	}
}

using IO::read;
using IO::write;
using IO::pc;
using IO::writesp;
using IO::writeln;

const int maxn = (1 << 20) + 50;

int n, m;
ll ans[maxn];
vector<pii> vc[maxn];

struct node {
	ll mn, smn, cnt;
	node(ll a = 0, ll b = 0, ll c = 0) : mn(a), smn(b), cnt(c) {}
};

inline node operator + (const node &a, const node &b) {
	node res;
	res.mn = min(a.mn, b.mn);
	res.smn = min(a.smn, b.smn);
	if (a.mn < b.mn) {
		res.smn = min(res.smn, b.mn);
	}
	if (a.mn > b.mn) {
		res.smn = min(res.smn, a.mn);
	}
	res.cnt = (a.mn == res.mn ? a.cnt : 0) + (b.mn == res.mn ? b.cnt : 0);
	return res;
}

struct vec {
	ll a0, a1, a2;
	vec(ll a = 0, ll b = 0, ll c = 0) : a0(a), a1(b), a2(c) {}
};

struct mat {
	ll a00, a01, a02, a10, a11, a12, a20, a21, a22;
	mat(ll a = 0, ll b = 0, ll c = 0, ll d = 0, ll e = 0, ll f = 0, ll g = 0, ll h = 0, ll i = 0) : a00(a), a01(b), a02(c), a10(d), a11(e), a12(f), a20(g), a21(h), a22(i) {}
} I;

inline bool operator == (const mat &a, const mat &b) {
	return a.a00 == b.a00 && a.a01 == b.a01 && a.a02 == b.a02 && a.a10 == b.a10 && a.a11 == b.a11 && a.a12 == b.a12 && a.a20 == b.a20 && a.a21 == b.a21 && a.a22 == b.a22;
}

inline bool operator != (const mat &a, const mat &b) {
	return a.a00 != b.a00 || a.a01 != b.a01 || a.a02 != b.a02 || a.a10 != b.a10 || a.a11 != b.a11 || a.a12 != b.a12 || a.a20 != b.a20 || a.a21 != b.a21 || a.a22 != b.a22;
}

inline vec operator + (const vec &a, const vec &b) {
	return vec(a.a0 + b.a0, a.a1 + b.a1, a.a2 + b.a2);
}

inline vec operator * (const vec &a, const mat &b) {
	vec res;
	res.a0 = a.a0 * b.a00 + a.a1 * b.a10 + a.a2 * b.a20;
	res.a1 = a.a0 * b.a01 + a.a1 * b.a11 + a.a2 * b.a21;
	res.a2 = a.a0 * b.a02 + a.a1 * b.a12 + a.a2 * b.a22;
	return res;
}
 
inline mat operator * (const mat &a, const mat &b) {
	mat res;
	res.a00 = a.a00 * b.a00 + a.a01 * b.a10 + a.a02 * b.a20;
	res.a01 = a.a00 * b.a01 + a.a01 * b.a11 + a.a02 * b.a21;
	res.a02 = a.a00 * b.a02 + a.a01 * b.a12 + a.a02 * b.a22;
	res.a10 = a.a10 * b.a00 + a.a11 * b.a10 + a.a12 * b.a20;
	res.a11 = a.a10 * b.a01 + a.a11 * b.a11 + a.a12 * b.a21;
	res.a12 = a.a10 * b.a02 + a.a11 * b.a12 + a.a12 * b.a22;
	res.a20 = a.a20 * b.a00 + a.a21 * b.a10 + a.a22 * b.a20;
	res.a21 = a.a20 * b.a01 + a.a21 * b.a11 + a.a22 * b.a21;
	res.a22 = a.a20 * b.a02 + a.a21 * b.a12 + a.a22 * b.a22;
	return res;
}

namespace SGT {
	node a[maxn << 1];
	vec b[maxn << 1];
	ll cov[maxn << 1];
	mat tag[maxn << 1], tmn[maxn << 1];
	
	inline void pushup(int x) {
		a[x] = a[x << 1] + a[x << 1 | 1];
		b[x] = b[x << 1] + b[x << 1 | 1];
		b[x].a2 = a[x].cnt;
	}
	
	inline void pushtmn(int x, mat y) {
		tmn[x] = tmn[x] * y;
		b[x] = b[x] * y;
	}
	
	inline void pushtag(int x, mat y) {
		tag[x] = tag[x] * y;
		tmn[x] = tmn[x] * y;
		b[x] = b[x] * y;
	}
	
	inline void pushcov(int x, ll y) {
		if (y <= a[x].mn) {
			return;
		}
		a[x].mn = cov[x] = y;
	}
	
	inline void pushdown(int x) {
		if (cov[x] != -1) {
			pushcov(x << 1, cov[x]);
			pushcov(x << 1 | 1, cov[x]);
			cov[x] = -1;
		}
		if (tag[x] != I || tmn[x] != I) {
			if (a[x << 1].mn == a[x].mn) {
				pushtag(x << 1, tmn[x]);
			} else {
				pushtag(x << 1, tag[x]);
			}
			if (a[x << 1 | 1].mn == a[x].mn) {
				pushtag(x << 1 | 1, tmn[x]);
			} else {
				pushtag(x << 1 | 1, tag[x]);
			}
			tag[x] = tmn[x] = I;
		}
	}
	
	void build(int rt, int l, int r) {
		cov[rt] = -1;
		tag[rt] = tmn[rt] = I;
		if (l == r) {
			a[rt] = node(0, 1e18, 1);
			b[rt] = vec(0, 0, 1);
			return;
		}
		int mid = (l + r) >> 1;
		build(rt << 1, l, mid);
		build(rt << 1 | 1, mid + 1, r);
		pushup(rt);
	}
	
	void update(int rt, int l, int r, int ql, int qr, ll x) {
		if (x <= a[rt].mn) {
			return;
		}
		if (ql <= l && r <= qr && x < a[rt].smn) {
			pushtmn(rt, mat(1, 0, 0, 0, 1, 0, 0, x - a[rt].mn, 1));
			pushcov(rt, x);
			return;
		}
		pushdown(rt);
		int mid = (l + r) >> 1;
		if (ql <= mid) {
			update(rt << 1, l, mid, ql, qr, x);
		}
		if (qr > mid) {
			update(rt << 1 | 1, mid + 1, r, ql, qr, x);
		}
		pushup(rt);
	}
	
	ll query(int rt, int l, int r, int ql, int qr) {
		if (ql <= l && r <= qr) {
			return b[rt].a0 + b[rt].a1;
		}
		pushdown(rt);
		int mid = (l + r) >> 1;
		ll res = 0;
		if (ql <= mid) {
			res += query(rt << 1, l, mid, ql, qr);
		}
		if (qr > mid) {
			res += query(rt << 1 | 1, mid + 1, r, ql, qr);
		}
		return res;
	}
}

void solve() {
	I.a00 = I.a11 = I.a22 = 1;
	n = read();
	m = read();
	for (int i = 1, x, y; i <= m; ++i) {
		x = read();
		y = read();
		vc[x].pb(i, y);
	}
	SGT::build(1, 1, m);
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < (int)vc[i].size(); ++j) {
			SGT::update(1, 1, m, vc[i][j].fst, j == (int)vc[i].size() - 1 ? m : vc[i][j + 1].fst - 1, vc[i][j].scd);
			ans[vc[i][j].fst] = SGT::query(1, 1, m, 1, vc[i][j].fst);
		}
		SGT::pushtag(1, mat(1, 0, 0, 1, 1, 0, 0, 0, 1));
	}
	for (int i = 1; i <= m; ++i) {
		writeln(ans[i]);
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2401ms
memory: 468788kb

input:

1000000 1000000
671688 1
193619 1
70068 1
729448 2
832062 64939
205871 1
749767 4
710152 4
993304 117427
157247 1
721584 4
6827 1
369183 2
476643 4
852855 753355
508841 6
245181 3
54307 1
137064 2
115503 2
66950 1
291862 1
770657 976136
191696 4
202434 3
529922 4
231829 2
589065 8
782988 799136
2784...

output:

1
1
1
1912354
3354971
555469
4114011
4395512
52363357726
697440
6578712
1
3592324
5566584
14871088552
7526096
3057721
332367
1644878
1387018
601240
6287130
36000529
3933576
4568550
22291424
6440571
31517994
84319940989
10571127
2675341
6175225
7634985
45895847
18882319
50616767
63113182
371152799285...

result:

wrong answer 9th numbers differ - expected: '52363093869', found: '52363357726'