QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253800#7523. Partially Free MealzhuibaoWA 170ms138728kbC++202.8kb2023-11-17 15:51:292023-11-17 15:51:30

Judging History

你现在查看的是最新测评结果

  • [2023-11-17 15:51:30]
  • 评测
  • 测评结果:WA
  • 用时:170ms
  • 内存:138728kb
  • [2023-11-17 15:51:29]
  • 提交

answer

#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>pi; typedef complex<double>cx;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(int i=a;i<=n;i++)
#define ref(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"Yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("1.out", ios::out);
//ifstream fin("1.in", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------

const int N=2e5+10,M=18;
int root[N],ans[N];
int n,idx;

struct node
{
    int x,y,id;
}g[N];

bool cmp(node a,node b)
{
    if(a.x^b.x)return a.x<b.x;
    return a.y<b.y;
}

bool cmp1(node a,node b)
{
    if(a.y^b.y)return a.y<b.y;
    return a.x<b.x;
}

struct seg
{
    int l,r,cnt,sum;
}tr[N*4+N*M];

int build(int l,int r)
{
    int p=++idx;
    if(l==r)return p;
    int mid=l+r>>1;
    tr[p].l=build(l,mid);
    tr[p].r=build(mid+1,r);
    return p;
}

int insert(int p,int l,int r,int pos,int x)
{
    int q=++idx;
    tr[q]=tr[p];
    if(l==r)
    {
        tr[q].cnt++;
        tr[q].sum+=x;
        return q;
    }
    int mid=l+r>>1;
    if(x<=mid)tr[q].l=insert(tr[p].l,l,mid,pos,x);
    else tr[q].r=insert(tr[q].r,mid+1,r,pos,x);
    tr[q].cnt=tr[tr[q].l].cnt+tr[tr[q].r].cnt;
    tr[q].sum=tr[tr[q].l].sum+tr[tr[q].r].sum;
    return q;
}

int query(int q,int l,int r,int k)
{
    if(l==r)
    {
        return tr[q].sum;
    }
    int cnt=tr[tr[q].l].cnt;
    int mid=l+r>>1;
    if(k<=cnt)
    {
        return query(tr[q].l,l,mid,k);
    }
    else
    {
        return tr[tr[q].l].sum+query(tr[q].r,mid+1,r,k-cnt);
    }
}

int W(int k,int x)
{
    return query(root[x],1,n,k);
}

void calc(int l,int r,int L,int R)
{
    if(l>r)return;
    int mid=l+r>>1;
    int res=1e18,pos=0;
    for(int i=max(L,mid);i<=R;i++)
    {
        int tmp=W(mid,i)+g[i].y;
        if(tmp<res)
        {
            res=tmp;pos=i;
        }
    }
    ans[mid]=res;
    calc(l,mid-1,L,pos);
    calc(mid+1,r,pos,R);
}

void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>g[i].x>>g[i].y;
    }
    sort(g+1,g+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        g[i].id=i;
    }
    sort(g+1,g+n+1,cmp1);
    root[0]=build(1,n);
    for(int i=1;i<=n;i++)
    {
        auto[x,y,id]=g[i];
        root[i]=insert(root[i-1],1,n,id,x);
    }
    calc(1,n,1,n);
    for(int i=1;i<=n;i++)
    {
        cout<<ans[i]<<'\n';
    }
}

AC

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9856kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 170ms
memory: 138728kb

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:

350098164
542379891
815516336
1634271747
2281723841
2288848823
2295081837
2436938324
3378947668
3729968912
3888786337
4450922472
4529407199
4668579114
5217871609
5748677760
6741335309
7240106251
7727932570
8316657022
8904518029
9850303712
10096632581
10289352744
10829176078
10986147364
11431637691
1...

result:

wrong answer 1st lines differ - expected: '1318594', found: '350098164'