QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116632 | #6630. Triangle Collection | lmeowdn# | 0 | 2ms | 12276kb | C++14 | 2.6kb | 2023-06-29 17:15:19 | 2024-05-31 18:29:28 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
const int N=2e5+5;
int n,Q,cnt,sum,yc[N],ys[N],a[N];
namespace SegT {
int ls[N<<1],rs[N<<1],s[N<<1],tag[N<<1],tot=1;
void build(int p,int l,int r) {
if(l==r) {s[p]=yc[l]-ys[l/2+1]; return;} int mid=l+r>>1;
build(ls[p]=++tot,l,mid), build(rs[p]=++tot,mid+1,r);
s[p]=max(s[ls[p]],s[rs[p]]);
}
void add(int p,int z) {s[p]+=z; tag[p]+=z;}
void psd(int p) {add(ls[p],tag[p]), add(rs[p],tag[p]), tag[p]=0;}
void add(int p,int l,int r,int x,int y,int z) {
if(l==x&&r==y) {add(p,z); return;} int mid=l+r>>1; psd(p);
if(y<=mid) add(ls[p],l,mid,x,y,z);
else if(x>mid) add(rs[p],mid+1,r,x,y,z);
else add(ls[p],l,mid,x,mid,z), add(rs[p],mid+1,r,mid+1,y,z);
s[p]=max(s[ls[p]],s[rs[p]]);
}
int qry() {return s[1];}
}
signed main() {
n=read(), Q=read();
rep(i,1,n) a[i]=read();
per(i,n,1) yc[i]=yc[i+1]+a[i]%2;
per(i,n,1) ys[i]=ys[i+1]+a[i]/2;
cnt=yc[1], sum=ys[1]*2;
SegT::build(1,1,n);
rep(i,1,Q) {
int l=read(), d=read();
if(a[l]&1) SegT::add(1,1,n,1,l,-1), cnt--;
SegT::add(1,1,n,1,min(2*l-1,n),a[l]/2), sum-=a[l]/2*2;
a[l]+=d;
if(a[l]&1) SegT::add(1,1,n,1,l,1), cnt++;
SegT::add(1,1,n,1,min(2*l-1,n),-a[l]/2), sum+=a[l]/2*2;
int p=cnt-SegT::qry();
int ans=p+(sum-2*p)/3;
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7868kb
input:
1 23 1485 1 -12 1 -30 1 -20 1 6 1 24 1 5 1 31 1 14 1 -34 1 -22 1 -45 1 37 1 46 1 9 1 22 1 -9 1 9 1 -46 1 -47 1 39 1 36 1 -36 1 50
output:
736 721 711 714 726 729 744 751 734 723 701 719 742 747 758 753 758 735 711 731 749 731 756
result:
wrong answer 1st numbers differ - expected: '491', found: '736'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 2ms
memory: 11972kb
input:
1999 2000 1 1 1 1 0 2 0 2 1 0 2 1 2 2 2 1 2 0 0 1 2 2 0 1 0 1 0 2 0 0 2 1 1 1 1 0 1 2 1 2 1 1 1 1 1 0 2 2 0 2 1 1 2 0 0 2 0 0 2 1 2 0 0 1 1 2 0 2 2 2 1 2 0 2 1 2 0 1 2 2 2 1 1 2 1 1 1 1 0 0 1 1 0 1 2 1 0 0 2 0 2 2 2 0 1 1 2 0 0 1 0 0 2 1 2 1 2 0 1 1 2 2 0 0 1 2 2 1 2 1 2 2 2 0 0 1 1 2 1 1 2 2 2 2 2 ...
output:
660 660 660 661 661 661 661 660 660 660 660 661 662 662 663 663 662 661 662 662 661 660 661 660 660 660 661 661 661 661 662 661 661 660 661 660 659 658 658 659 659 658 659 660 660 660 660 660 660 659 659 659 659 659 659 659 659 660 659 658 658 658 658 657 657 657 658 657 656 657 657 657 656 656 655 ...
result:
wrong answer 615th numbers differ - expected: '660', found: '661'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 0ms
memory: 12276kb
input:
2000 1999 0 1 0 3 0 1 0 0 0 0 0 0 0 2 0 0 0 0 3 1 1 0 2 0 0 3 0 0 0 0 0 4 0 0 1 0 1 0 0 0 0 1 2 1 0 0 0 0 7 0 1 3 1 0 1 1 0 3 2 1 0 1 1 3 3 1 0 2 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 2 3 0 1 0 3 3 0 0 0 0 1 0 1 2 0 0 2 2 0 1 2 1 2 0 0 0 1 1 0 1 2 0 0 0 0 2 0 5 0 0 0 0 0 1 0 0 2 0 1 2 0 1 0 0 0 2 0 ...
output:
670 670 670 670 670 670 670 670 670 671 671 671 671 672 672 672 671 671 671 672 672 672 671 671 670 670 669 669 668 668 669 669 669 669 669 669 668 668 668 668 667 667 666 666 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 666 666 667 667 668 668 668 668 668 668 668 668 667 667 ...
result:
wrong answer 1st numbers differ - expected: '666', found: '670'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%