QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533762#3042. Hilbert's HotelRainPPRWA 0ms3684kbC++203.9kb2024-08-26 13:15:462024-08-26 13:15:46

Judging History

你现在查看的是最新测评结果

  • [2024-08-26 13:15:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3684kb
  • [2024-08-26 13:15:46]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define oj 1
#define qdezoj 1

#if oj
#define D(x) ({ (x); })
#else
#define D(x) ({ decltype(x) __x = x; cerr << "| DEBUG #" << __LINE__ << " in " << __FUNCTION__ << "() : " << ##x << " = [" << __x << "]" << endl; (__x); })
#endif

#define endl "\n"
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))

#define open_file(x) ({ \
	freopen(x".in", "r", stdin); \
	freopen(x".out", "w", stdout); \
})

using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;

#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x) / gcd(x, y) * (y))

// -----------------------------------------------------------------------------

constexpr u64 MOD = 1e9 + 7;

u64 qpow(u64 a, u32 b) {
	u64 r = 1;
	for (; b; b >>= 1) {
		if (b & 1)
			r = r * a % MOD;
		a = a * a % MOD;
	}
	return r % MOD;
}

namespace S0 {
	void Main() {
		cin.seekg(0);
		u32 Q;
		cin >> Q;
		u32 now = 0;
		while (Q--) {
			u32 op;
			cin >> op;
			if (op == 1) {
				u32 k;
				cin >> k;
				assert(k == 0);
				++now;
			}
			else if (op == 2) {
				u32 g, x;
				cin >> g >> x;
				if (g == 0)
					--x;
				if (x == 0)
					cout << 0 << endl;
				else
					cout << qpow(2, now - g) * (2 * x - 1) % MOD << endl;
			}
			else if (op == 3) {
				u32 x;
				cin >> x;
				if (x == 0)
					cout << 0 << endl;
				else {
					i64 t = __builtin_ctz(x);
					cout << Max(now - t, 0) << endl;
				}
			}
		}
	}
}

namespace Sp {
	constexpr size_t X = 3e5 + 10;
	
	namespace seg {
		struct node {
			u32 l, r;
			u64 sum;
		} a[X << 2];
		
		u32 pos[X];
		
		void push_up(u32 k) {
			a[k].sum = a[k << 1].sum + a[k << 1 | 1].sum;
		}
		
		void build(u32 k, u32 l, u32 r) {
			a[k] = node{l, r, 0};
			if (l == r) {
				pos[l] = k;
				return;
			}
			int mid = (l + r) >> 1;
			build(k << 1, l, mid);
			build(k << 1 | 1, mid + 1, r);
		}
		
		void modify(u32 x, u32 v) {
			u32 k = pos[x];
			a[k].sum = v;
			while (k != 1) {
				k >>= 1;
				push_up(k);
			}
		}
		
		u64 query(u32 k, u32 p, u32 q) {
			u32 l = a[k].l, r = a[k].r;
			if (l >= p && r <= q)
				return a[k].sum;
			u32 mid = (l + r) >> 1;
			if (q <= mid)
				return query(k << 1, p, q);
			if (p >= mid + 1)
				return query(k << 1 | 1, p, q);
			return query(k << 1, p, q) + query(k << 1 | 1, p, q);
		}
		
		u32 bin(u64 x) {
			u32 k = 1;
			while (a[k].l != a[k].r) {
				if (a[k << 1].sum >= x)
					k <<= 1;
				else {
					x -= a[k << 1].sum;
					k = k << 1 | 1; 
				}
			}
			return a[k].l;
		}
	}
	
	void Main() {
		cin.seekg(0);
		u32 Q;
		cin >> Q;
		seg::build(1, 1, Q);
		u32 now = 0;
		u64 sum = 0;
		while (Q--) {
			u32 op;
			cin >> op;
			if (op == 1) {
				u32 k;
				cin >> k;
				assert(k > 0);
				seg::modify(++now, k);
				sum += k;
			}
			else if (op == 2) {
				u32 g, x;
				cin >> g >> x;
				if (g == 0)
					cout << (sum + x - 1 + MOD) % MOD << endl;
				else if (g == now)
					cout << (x - 1 + MOD) % MOD << endl;
				else
					cout << (seg::query(1, g + 1, now) + x - 1 + MOD) % MOD << endl;
			}
			else if (op == 3) {
				u32 k;
				cin >> k;
				++k;
				if (k > sum)
					cout << 0 << endl;
				else
					cout << seg::bin(sum - k + 1) << endl;
			}
		}
	}
}

namespace Sqwq {
	void Main() {
		cin.seekg(0);
		cout << 114514 << endl;
	/*	while (true) {
			int *p = new int[10000000];
			memset(p, 0xcf, sizeof(int) * 10000000);
		}*/
	}
}

void Main() {
	u32 Q;
	cin >> Q;
	bool all0 = true;
	bool allp = true;
	while (Q--) {
		int op;
		cin >> op;
		int x, g;
		cin >> x;
		if (op == 1) {
			all0 &= x == 0;
			allp &= x != 0;
		}
		if (op == 2)
			cin >> g;
	}
	if (all0)
		S0::Main();
	else if (allp)
		Sp::Main();
	else
		Sqwq::Main();
}

// -----------------------------------------------------------------------------

signed main() {
	#if oj
	#if qdezoj
//	open_file("hotel");
	#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	#else
	cerr << "LOCAL" << endl;
	#endif
	Main();
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3684kb

input:

10
3 0
1 3
2 1 2
1 0
3 10
2 2 5
1 5
1 0
3 5
2 3 3

output:

114514

result:

wrong answer 1st lines differ - expected: '0', found: '114514'