QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#850336 | #9528. New Energy Vehicle | BUET_ALUCHASHI# | WA | 0ms | 3872kb | C++17 | 6.3kb | 2025-01-10 01:12:59 | 2025-01-10 01:12:59 |
Judging History
answer
#include <bits/stdc++.h>
#define lli long long
#define plli pair<lli, lli>
#define MAX 1e6 + 6
lli MOD = 1000000007LL;
using namespace std;
//segment tree updates precisely doesn,t add
struct DataSet{
lli mx;
};
struct SegmentTree
{
int N;
vector<DataSet> segtree;
SegmentTree(int n){
N=n;
segtree.resize(4*N);
}
DataSet combine(DataSet l, DataSet r){
DataSet res;
res.mx = max(l.mx , r.mx);
return res;
}
DataSet make_dataSet(lli val){
DataSet res;
res.mx = val;
return res;
}
void build(vector<lli> &a, int root, int arrleft, int arrright){
if (arrleft == arrright){
segtree[root] = make_dataSet(a[arrleft]);
}
else{
int arrmid = (arrleft + arrright) / 2;
build(a, root * 2, arrleft, arrmid);
build(a, root * 2 + 1, arrmid + 1, arrright);
segtree[root] = combine(segtree[root * 2], segtree[root * 2 + 1]);
}
}
void point_update(int root, int arrleft, int arrright, int pos, lli new_val)
{
if ((arrleft > pos) || (arrright < pos))
return;
if (arrleft == arrright){
segtree[root] = make_dataSet(new_val);
}
else{
int arrmid = (arrleft + arrright) / 2;
point_update(root * 2, arrleft, arrmid, pos, new_val);
point_update(root * 2 + 1, arrmid + 1, arrright, pos, new_val);
segtree[root] = combine(segtree[root * 2], segtree[root * 2 + 1]);
}
}
int queryNonZeroInd(int root, int arrleft, int arrright){
if ((arrleft > arrright))
return -1;
if(arrleft==arrright){
return arrleft;
}
int mid=(arrleft+arrright)>>1;
int fir=segtree[2*root].mx;
int sec=segtree[2*root+1].mx;
if(fir>0){
return queryNonZeroInd(2*root,arrleft,mid);
}
if(sec>0){
return queryNonZeroInd(2*root+1,mid+1,arrright);
}
return -1;
}
// DataSet query(int root, int arrleft, int arrright, int L, int R){
// // root has a connection to arrleft or arrright not with quL or quR
// if ((L > R) || (arrleft > arrright))
// return make_dataSet(0);
// if ((L <= arrleft) && (R >= arrright))
// return segtree[root];
// if ((L > arrright) || (R < arrleft))
// return make_dataSet(0);
// int arrmid = (arrleft + arrright) / 2;
// return combine(query(root * 2, arrleft, arrmid, L, R),
// query(root * 2 + 1, arrmid + 1, arrright, L, R));
// }
};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
vector<int> cap(n+1);
vector<int> curcap(n+1);
for(int i=1;i<=n;i++){
cin>>cap[i];
curcap[i]=cap[i];
}
vector<pair<int,int>> poschr(m+1);
for(int i=1;i<=m;i++){
cin>>poschr[i].first>>poschr[i].second;
}
for(int i=2;i<=m;i++){
poschr[i].first-=poschr[i-1].first;
}
// sort(poschr.begin()+1,poschr.end());
vector<int> inds(n+1,m+1);
vector<int> next(m+1,m+1);
for(int i=m;i>0;i--){
next[i]=inds[poschr[i].second];
inds[poschr[i].second]=i;
}
SegmentTree stree(m+5); //kontar capacity full ache
for(int i=1;i<=n;i++){
stree.point_update(1,1,m+1,inds[i],1);
}
lli onetime=0;
for(int i=1;i<=n;i++){
if(inds[i]==m+1){
onetime+=cap[i];
curcap[i]=0;
}
}
// for(int i=1;i<=m;i++){
// cout<<next[i]<<"\n";
// }
// cout<<onetime<<"\n";
lli ans=0;
// lli cur=0;
for(int i=1;i<=m;i++){ // ith station e jete parbo?
while(true){
int ind=stree.queryNonZeroInd(1,1,m+1);
// cout<<ind<<" "<<poschr[i].first<<" "<<onetime<<" "<<ans<<" inin\n";
if(ind==m+1){
if(onetime>=poschr[i].first){
onetime-=poschr[i].first;
ans+=poschr[i].first;
// cout<<ans<<"kakak\n";
curcap[poschr[i].second]=cap[poschr[i].second];
stree.point_update(1,1,m+1,i,0);
stree.point_update(1,1,m+1,next[i],1);
break;
}
ans+=onetime;
onetime=0;
break;
}
if(curcap[poschr[ind].second]>poschr[i].first){
curcap[poschr[ind].second]-=poschr[i].first;
ans+=poschr[i].first;
curcap[poschr[i].second]=cap[poschr[i].second];
stree.point_update(1,1,m+1,i,0);
stree.point_update(1,1,m+1,next[i],1);
break;
}
poschr[i].first-=curcap[poschr[ind].second];
ans+=curcap[poschr[ind].second];
curcap[poschr[ind].second]=0;
stree.point_update(1,1,m+1,ind,0);
stree.point_update(1,1,m+1,next[ind],1);
// for(int i=1;i<=n;i++){
// cout<<curcap[i]<<' ';
// }cout<<"\n";
// cout<<onetime<<"\n";
}
// for(int i=1;i<=n;i++){
// cout<<curcap[i]<<' ';
// }cout<<"\n";
// cout<<onetime<<"\n";
// if(ans<m){
// break;
// }
}
// cout<<ans<<" kaka\n";
// ans=+onetime;
// cout<<onetime<<"\n";
for(int i=1;i<=n;i++){
// cout<<curcap[i]<<"\n";
onetime+=curcap[i];
// cout<<ans<<"\n";
}
cout<<ans+onetime<<"\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
12 9
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3628kb
input:
6 3 2 2 2 2 6 1 7 1 2 2 3 3 2 1 6 2 2 3 2 2 5 1 7 2 9 1 2 2 3 3 2 1 6 2 1 1 999999999 1000000000 1 1 1 1000000000 1000000000 1
output:
9 8 4 8 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '8'