P6627
Solution
我们称一个初等的优惠为
那么我们的操作事实上是这样的:
然后离散化+前缀和即可。
注意为了特判极端情况,我加了个
#include<bits/stdc++.h>
#define int long long
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=4e5+10;
int n,tot,w[MAXN],lsh[MAXN];
vector<pair<pair<int,int>,int>> upd;
void insert(int l,int r,int w) {
lsh[++tot]=l,lsh[++tot]=r+1;
upd.push_back({{l,r},w});
return ;
}
int ans,pos;
void check(int W,int Pos) {
if(W>ans) return ans=W,pos=Pos,void();
if(W<ans) return ;
if(W==ans&&((abs(Pos)<abs(pos))||(abs(Pos)==abs(pos)&&Pos>pos))) return ans=W,pos=Pos,void();
return ;
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
insert(0,0,0);
int mx=1000000000;
ffor(i,1,n) {
int op; cin>>op;
if(op==1) {
int l,r,w; cin>>l>>r>>w;
insert(l,r,w);
}
if(op==2) {
int pos,v;
cin>>pos>>v;
insert(pos,pos,v);
}
if(op==3) {
int pos,v;
cin>>pos>>v;
insert(-mx-1,pos-1,v);
insert(pos+1,mx+1,v);
}
}
sort(lsh+1,lsh+tot+1);
tot=unique(lsh+1,lsh+tot+1)-lsh-1;
for(auto pr:upd) {
int l=pr.first.first,r=pr.first.second+1,v=pr.second;
l=lower_bound(lsh+1,lsh+tot+1,l)-lsh;
r=lower_bound(lsh+1,lsh+tot+1,r)-lsh;
w[l]^=v,w[r]^=v;
}
ffor(i,1,tot) w[i]^=w[i-1];
ffor(i,1,tot) check(w[i],lsh[i]);
ffor(i,1,tot-1) check(w[i],lsh[i+1]-1);
cout<<ans<<' '<<pos<<'\n';
return 0;
}
感觉,这题,难度,差不多是,红~橙。