QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#766254 | #7523. Partially Free Meal | ucup-team4352 | WA | 246ms | 49236kb | C++23 | 2.8kb | 2024-11-20 16:45:20 | 2024-11-20 16:45:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int n,pos[maxn],loc[maxn];
struct Data{
int x,y;
}a[maxn];
int b[maxn],c[maxn];
bool comp(Data A,Data B) {
if(A.y==B.y) return A.x>B.x;
return A.y<B.y;
}
int cnt,sum[maxn*60],L[maxn*60],R[maxn*60];
void update(int rt,int l,int r,int x) {
sum[rt]++;
if(l==r) return;
int mid=l+r>>1;
if(x<=mid) {
if(!L[rt]) L[rt]=++cnt;
update(L[rt],l,mid,x);
}
else {
if(!R[rt]) R[rt]=++cnt;
update(R[rt],mid+1,r,x);
}
}
int query(int rt,int l,int r,int x) {
if(x>=r) return sum[rt];
int mid=l+r>>1;
if(x<=mid) {
int res=0;
if(L[rt]) res=query(L[rt],l,mid,x);
return res;
}
else {
int res=0;
if(L[rt]) res+=sum[L[rt]];
if(R[rt]) res+=query(R[rt],mid+1,r,x);
return res;
}
}
ll res;
struct Node{
int js[maxn<<2];
ll sum[maxn<<2];
void update(int rt,int l,int r,int p) {
js[rt]++;
sum[rt]+=b[p];
if(l==r) return;
int mid=l+r>>1;
if(p<=mid) update(rt<<1,l,mid,p);
else update(rt<<1|1,mid+1,r,p);
}
void query(int rt,int l,int r,int p) {
if(!p) return;
if(l==r) {
res+=(ll)p*b[l];
return;
}
int mid=l+r>>1;
if(js[rt<<1]<=p) {
res+=sum[rt<<1];
query(rt<<1|1,mid+1,r,p-js[rt<<1]);
}
else query(rt<<1,l,mid,p);
}
}T;
#define pii pair<int,int>
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;++i) cin>>a[i].x>>a[i].y,b[i]=a[i].x;
sort(a+1,a+1+n,comp);
sort(b+1,b+1+n);
int m=unique(b+1,b+1+n)-b-1;
for(int i=1;i<=n;++i) c[i]=lower_bound(b+1,b+1+m,a[i].x)-b;
pos[1]=1;
update(0,0,2e9,a[1].x);
loc[1]=1;
vector<pii>st;
st.push_back({1,1});
for(int i=2;i<=n;++i) {
while(!st.empty()){
int pos=query(0,0,2e9,a[i].x+a[i].y-a[st.back().first].y)+1;
if(pos>st.back().second)break;
st.pop_back();
}
if(st.empty())st.push_back({i,1});
else{
st.push_back({i,min(query(0,0,2e9,a[i].x+a[i].y-a[st.back().first].y)+1,st.back().first+1)});
}
update(0,0,2e9,a[i].x);
}
for(auto u:st){
loc[u.second]=u.first;
}
int now=1;
for(int i=1;i<=n;i++){
loc[i]=max(loc[i],loc[i-1]);
// cout<<a[loc[i]].y<<"\n";
//k=i的答案为,maxb取b[loc[i]]时的前k大的sum
while(now<loc[i]) {
T.update(1,1,m,c[now]);
now++;
}
res=(ll)a[loc[i]].x+a[loc[i]].y;
T.query(1,1,m,i-1);
cout<<res<<'\n';
}
return 0;
}
/*
20
8 22188
12 18475
3 8570
12 9335
1 24723
13 13613
5 4993
15 25931
4 25939
6 24950
5 23023
14 20460
11 26026
6 17594
14 8982
12 17967
5 6939
2 30096
1 21322
10 12301
8
1 2741
8 21767
15 6262
1 10427
12 466
4 32333
14 24830
5 21820
4998
6949
8583
9009
9374
12350
13675
17662
18047
18567
20566
21429
22303
23143
24844
25077
25092
26085
26183
30255
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13768kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 246ms
memory: 49236kb
input:
200000 466436993 804989151 660995237 756645598 432103296 703610564 6889895 53276988 873617076 822481192 532911431 126844295 623111499 456772252 937464699 762157133 708503076 786039753 78556972 5436013 582960979 398984169 786333369 325119902 930705057 615928139 924915828 506145001 164984329 208212435...
output:
1318594 3208018 9439868 16561582 41100150 67812131 13751811 16969221 20474954 24404868 30390740 36622590 43744304 52122619 61331022 71110873 81076105 91822932 102671939 114109633 126854884 140055155 153878110 168512754 183849441 200112397 216554901 233273492 250324248 267805405 285348393 303023210 3...
result:
wrong answer 3rd lines differ - expected: '5570526', found: '9439868'