QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#603880#9242. An Easy Geometry Problemxi_xiWA 12ms14532kbC++145.0kb2024-10-01 20:33:252024-10-01 20:33:26

Judging History

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

  • [2024-10-01 20:33:26]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:14532kb
  • [2024-10-01 20:33:25]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define int long long
using namespace std;

const int maxn = 1e6 + 5;
const int base = 100;
const int mod = 998244353;
int n, q, k, b, a[maxn];
int pw[maxn], sum[maxn], ans[maxn];
struct node{
	struct nd{
		int l, r, laz;
		int sum;
	}tree[maxn << 2];
	int len(int p){return tree[p].r - tree[p].l + 1;}
	void pushup(int p){
		tree[p].sum = (tree[p << 1].sum + tree[p << 1 | 1].sum * pw[len(p << 1)]) % mod; 
	}
	void build(int p, int l, int r){
		tree[p].l = l;tree[p].r = r;
		if(l == r){
			tree[p].sum = a[l] * base % mod;
			return;
		}
		int mid = l + r >> 1;
		build(p << 1, l, mid);
		build(p << 1 | 1, mid + 1, r);
		pushup(p);
	}
	void add(int p, int x){
		(tree[p].laz += x) %= mod;
		(tree[p].sum += sum[len(p)] % mod * x) %= mod;
	}
	void pushdown(int p){
		int laz = tree[p].laz;
		if(laz){
			add(p << 1, laz);
			add(p << 1 | 1, laz);
			tree[p].laz = 0;
		}
	}
	void update(int p, int l, int r, int x){
		if(l <= tree[p].l && tree[p].r <= r){
			add(p, x);
			return;
		}
		pushdown(p);
		int mid = tree[p].l + tree[p].r >> 1;
		if(l <= mid) update(p << 1, l, r, x);
		if(mid < r) update(p << 1 | 1, l, r, x);
		pushup(p);
	}
	int query(int p, int l, int r){
//		if(tree[p].l > r || tree[p].r < l) return 0;
		if(l <= tree[p].l && tree[p].r <= r) return tree[p].sum;
		pushdown(p);
		int mid = tree[p].l + tree[p].r >> 1;
		if(l > mid) return query(p << 1 | 1, l, r);
		if(r <= mid) return query(p << 1, l, r);
		return (query(p << 1, l, r) + query(p << 1 | 1, l, r) * pw[mid - min(l, tree[p << 1].l) + 1]) % mod;
	}
}T1;

struct node1{
	struct nd{
		int l, r, laz;
		int sum;
	}tree[maxn << 2];
	int len(int p){return tree[p].r - tree[p].l + 1;}
	void pushup(int p){
		tree[p].sum = (tree[p << 1].sum * pw[len(p << 1 | 1)] + tree[p << 1 | 1].sum) % mod; 
	}
	void build(int p, int l, int r){
		tree[p].l = l;tree[p].r = r;
		if(l == r){
			tree[p].sum = a[l] * base % mod;
			return;
		}
		int mid = l + r >> 1;
		build(p << 1, l, mid);
		build(p << 1 | 1, mid + 1, r);
		pushup(p);
	}
	void add(int p, int x){
		(tree[p].laz += x) %= mod;
		(tree[p].sum += sum[len(p)] % mod * x) %= mod;
	}
	void pushdown(int p){
		int laz = tree[p].laz;
		if(laz){
			add(p << 1, laz);
			add(p << 1 | 1, laz);
			tree[p].laz = 0;
		}
	}
	void update(int p, int l, int r, int x){
		if(l <= tree[p].l && tree[p].r <= r){
			add(p, x);
			return;
		}
		pushdown(p);
		int mid = tree[p].l + tree[p].r >> 1;
		if(l <= mid) update(p << 1, l, r, x);
		if(mid < r) update(p << 1 | 1, l, r, x);
		pushup(p);
	}
	int query(int p, int l, int r){
		if(l <= tree[p].l && tree[p].r <= r) return tree[p].sum;
		pushdown(p);
		int mid = tree[p].l + tree[p].r >> 1;
		if(l > mid) return query(p << 1 | 1, l, r);
		if(r <= mid) return query(p << 1, l, r);
//		cout << "**************\n";
//		cout << p << ' ' << tree[p].l << ' ' << tree[p].r << ' ' << l << ' ' << r << ' ' << mid << '\n';
//		cout << query(p << 1, l, r) << ' ' << pw[len(p << 1 | 1)] << ' ' << query(p << 1 | 1, l, r) << '\n';
		return (query(p << 1, l, r) * pw[min(r, tree[p].r) - mid] + query(p << 1 | 1, l, r)) % mod;
	}
}T2;

bool check(int i, int mid){
	int x = T1.query(1, i + 1, i + mid) % mod;
	int y = T2.query(1, i - mid, i - 1) % mod;
//	cout << "2 2 " << T2.query(1, 2, 2) << '\n';
//	cout << "2 3 " << T2.query(1, 3, 4) << '\n'; 
//	cout << i << ' ' << mid << " :\n";
//	cout << x << ' ' << y << ' ' << (x - y + mod) % mod << ' ' << ans[mid] << '\n';
	return (x - y + mod) % mod == (ans[mid] % mod + mod) % mod;
}

signed main(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
	
	cin >> n >> q >> k >> b; k = (k + mod) % mod, b = (b + mod) % mod;
	for(int i = 1; i <= n; i++) cin >> a[i], a[i] = (a[i] % mod + mod) % mod;
	pw[0] = 1; for(int i = 1; i <= n; i++) pw[i] = pw[i - 1] * base % mod;
	for(int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + pw[i]) % mod;
	T1.build(1, 1, n);T2.build(1, 1, n);
	for(int i = 1; i <= n; i++) ans[i] = (ans[i - 1] + pw[i] * ((k * i + b) % mod + mod) % mod) % mod;
//	for(int i = 1; i <= n; ++i) cout << T1.query(1, i, i) << ' '; cout << '\n';
//	for(int i = 1; i <= n; ++i) cout << T2.query(1, i, i) << ' '; cout << '\n';
	while(q--){
		int op;cin >> op;
		if(op == 1){
			int l, r, v;cin >> l >> r >> v;
			v = v % mod + mod;
			v %= mod;
			T1.update(1, l, r, v);
			T2.update(1, l, r, v);
		}else{
			int i;cin >> i;
			int l = 1, r = min(n - i, i - 1), ans = 0;
			while(l <= r){
				int mid = l + r >> 1;
				if(check(i, mid)) ans = mid, l = mid + 1;
				else r = mid - 1;
			}
			cout << ans << '\n';
		}
		
	//for(int i = 1; i <= n; ++i) cout << T1.query(1, i, i) << ' '; cout << '\n';
	//for(int i = 1; i <= n; ++i) cout << T2.query(1, i, i) << ' '; cout << '\n';
		
	}
//	for(int i = 1; i <= n; i++) cout << T1.query(1, i, i) << " ";cout << '\n';
	
    return 0;
}
/*
9 1 4 5
1 2 3 4 5 13 16 19 22
2 5

6 6 6 2
1 5 9 10 15 18
2 2
1 3 3 -3
2 2
1 3 4 3
2 3
2 4
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 9816kb

input:

6 6 6 2
1 5 9 10 15 18
2 2
1 3 3 -3
2 2
1 3 4 3
2 3
2 4

output:

1
0
2
0

result:

ok 4 number(s): "1 0 2 0"

Test #2:

score: -100
Wrong Answer
time: 12ms
memory: 14532kb

input:

5000 5000 2 0
-329 -328 -327 -326 -325 -324 -323 -322 -321 -320 -319 -318 -317 -316 -315 -314 -313 -312 -311 -310 -309 -308 -307 -306 -305 -304 -303 -302 -301 -300 -299 -298 -297 -296 -295 -294 -293 -292 -291 -290 -289 -288 -287 -286 -285 -284 -283 -282 -281 -280 -279 -278 -277 -276 -275 -274 -273 -...

output:

2
1
5
5
1
1
2
5
1
1
1
1
1
1
2
2
1
10
10
1
1
1
1
2
1
1
1
1
1
1
4
2
4
2
4
1
2
1
1
1
1
1
1
5
2
1
1
2
2
1
1
1
1
8
3
1
1
2
2
1
2
2
2
1
1
2
1
1
1
1
1
25
1
1
1
1
1
1
1
1
1
4
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
5
1
13
1
2
5
5
5
1
2
2
4
1
1
1
1
1
1
1
3
1
2
1
1
1
1
7
1
1
1
1
2
1
1
2
5
1
0
1
8
2
5
1
5
1
1
1
5
7
1
...

result:

wrong answer 2nd numbers differ - expected: '304', found: '1'