QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#647034 | #9242. An Easy Geometry Problem | icpc_zhzx034# | RE | 16ms | 41424kb | C++14 | 4.4kb | 2024-10-17 11:10:53 | 2024-10-17 11:10:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll,ll> P;
#define _for(x,y,z) for (int x(y),_(z); x<=_; ++x)
#define _rep(x,y,z) for (int x(y),_(z); x>=_; --x)
inline ll read(){ ll x; scanf("%lld",&x); return x; }
inline void _init(){
#ifdef LOCAL
assert(freopen("test.in", "r", stdin));
assert(freopen("test.out", "w", stdout));
#endif
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
}
const int N = 2e5 + 5;
const ll base = 2131073233ll;
const ll mod = (ll)1e18 + 3;
ll pw[N], qz[N];
ll n, q, k, B, a[N], b[N], c[N];
struct Hsh{
ll hsh, sz;
Hsh(ll a=0, ll b=0){ hsh=a, sz=b; }
};
Hsh operator+ (Hsh A, Hsh B){
return Hsh((A.hsh+(__int128)pw[A.sz]*B.hsh)%mod, A.sz+B.sz);
}
struct Seg1{
Hsh t[4*N]; ll tag[4*N],len[4*N];
void pushup(ll pos){
t[pos]=t[pos<<1]+t[pos<<1|1];
}
void upd(ll pos,ll v){
t[pos].hsh = (t[pos].hsh + (__int128)(v + mod) * qz[t[pos].sz-1]) % mod;
tag[pos] = (tag[pos] + v) % mod;
}
void pushdown(ll pos){
if(tag[pos]){
upd(pos<<1, tag[pos]);
upd(pos<<1|1, tag[pos]);
tag[pos]=0;
}
}
void build(ll l,ll r,ll pos){
if(l==r){
t[pos] = Hsh(b[l]<0?mod+b[l]:b[l], 1);
// cout<<"at "<<l<<" is "<<(b[l]<0?mod+b[l]:b[l])<<endl;
return;
}
ll mid=(l+r)>>1;
if(l<=mid) build(l,mid,pos<<1);
if(mid<r) build(mid+1,r,pos<<1|1);
pushup(pos);
}
void update(ll l,ll r,ll ql,ll qr,ll v,ll pos){
if(ql<=l && r<=qr){
upd(pos, v);
return;
}
ll mid=(l+r)>>1;
pushdown(pos);
if(ql<=mid) update(l,mid,ql,qr,v,pos<<1);
if(mid<qr) update(mid+1,r,ql,qr,v,pos<<1|1);
pushup(pos);
}
Hsh ans;
void query(ll l,ll r,ll ql,ll qr,ll pos){
if(ql>qr) return;
if(ql<=l && r<=qr) {
ans = ans + t[pos];
return;
}
ll mid=(l+r)>>1;
pushdown(pos);
if(ql<=mid) query(l,mid,ql,qr,pos<<1);
if(mid<qr) query(mid+1,r,ql,qr,pos<<1|1);
pushup(pos);
}
ll hash(ll l,ll r,ll op=0){
ans=Hsh(0,0);
query(1,n,l,r,1);
// if(op) cout<<"between "<<l<<" "<<r<<" hash = "<<ans.hsh<<endl;
return ans.hsh;
}
}S;
struct Seg2{
Hsh t[4*N]; ll tag[4*N],len[4*N];
void pushup(ll pos){
t[pos]=t[pos<<1|1]+t[pos<<1];
}
void upd(ll pos,ll v){
t[pos].hsh = (t[pos].hsh + (__int128)(v + mod) * qz[t[pos].sz-1]) % mod;
tag[pos] = (tag[pos] + v) % mod;
}
void pushdown(ll pos){
if(tag[pos]){
upd(pos<<1, tag[pos]);
upd(pos<<1|1, tag[pos]);
tag[pos]=0;
}
}
void build(ll l,ll r,ll pos){
if(l==r){
t[pos] = Hsh(b[l]<0?mod+b[l]:b[l], 1);
// cout<<"at "<<l<<" is "<<(b[l]<0?mod+b[l]:b[l])<<endl;
return;
}
ll mid=(l+r)>>1;
if(l<=mid) build(l,mid,pos<<1);
if(mid<r) build(mid+1,r,pos<<1|1);
pushup(pos);
}
void update(ll l,ll r,ll ql,ll qr,ll v,ll pos){
if(ql<=l && r<=qr){
upd(pos, v);
return;
}
ll mid=(l+r)>>1;
pushdown(pos);
if(ql<=mid) update(l,mid,ql,qr,v,pos<<1);
if(mid<qr) update(mid+1,r,ql,qr,v,pos<<1|1);
pushup(pos);
}
Hsh ans;
void query(ll l,ll r,ll ql,ll qr,ll pos){
if(ql>qr) return;
if(ql<=l && r<=qr) {
ans = t[pos] + ans;
return;
}
ll mid=(l+r)>>1;
pushdown(pos);
if(ql<=mid) query(l,mid,ql,qr,pos<<1);
if(mid<qr) query(mid+1,r,ql,qr,pos<<1|1);
pushup(pos);
}
ll hash(ll l,ll r,ll op=0){
ans=Hsh(0,0);
query(1,n,l,r,1);
// if(op) cout<<"between "<<l<<" "<<r<<" hash = "<<ans.hsh<<endl;
return ans.hsh;
}
}T;
void init() {
pw[0] = qz[0] = 1;
for(ll i=1;i<N;i++) pw[i]=(__int128)pw[i-1]*base%mod;
for(ll i=1;i<N;i++) qz[i]=(qz[i-1]+pw[i])%mod;
}
void procedure() {
n=read(), q=read(), k=read(), B=2*read();
for(ll i=1;i<=n;i++){
a[i]=read();
b[i]=2*a[i]-i*k+1e9;
}
// for(ll i=1;i<=n;i++) cout<<b[i]<<" "; cout<<endl;
S.build(1,n,1); T.build(1,n,1);
while(q--){
ll op=read();
if(op==1){
ll l=read(), r=read(), v=read()*2;
S.update(1,n,l,r,v,1); T.update(1,n,l,r,v,1);
}else{
ll x=read();
ll l=1, r=min(x-1, n-x), ans=0;
S.update(1,n,1,x-1,B,1);
while(l<=r){
ll mid=(l+r)>>1;
if(S.hash(x-mid,x-1,1) == T.hash(x+1,x+mid,1)){
ans=mid; l=mid+1;
}else r=mid-1;
}
S.update(1,n,1,x-1,-B,1);
// cout<<ans<<endl;
printf("%lld\n", ans);
}
// cout<<"now "; for(ll i=1;i<=n;i++) cout<<S.hash(i,i)<<" "; cout<<endl;
}
}
int main() {
_init(), init();
int T=1;
while(T--) procedure();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 41168kb
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: 0
Accepted
time: 16ms
memory: 41424kb
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 304 73 29 61 292 139 48 17 99 6 5 53 93 3 91 65 29 33 306 21 24 17 21 281 12 16 1 33 7 18 96 7 40 39 13 7 46 43 16 1 72 33 16 22 5 6 189 27 1 35 107 43 34 3 27 20 21 44 56 96 36 2 27 22 30 32 6 5 105 27 37 12 58 2 21 154 17 110 57 3 7 33 15 24 94 68 25 1 14 10 4 10 2 25 39 36 33 164 11 19 181 11 3...
result:
ok 3337 numbers
Test #3:
score: -100
Runtime Error
input:
5000 5000 2 0 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 86...