답안 #520189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520189 2022-01-28T17:38:05 Z A_D 사탕 분배 (IOI21_candies) C++17
29 / 100
958 ms 18004 KB
#include "candies.h"

#include <bits/stdc++.h>

using namespace std;
vector<pair<int,int>> vec;
const int N=2e5+100;
int seg[4*N];
int seg2[4*N];
void fix(int p,int s,int e)
{
    if(s!=e){
        if(seg2[p]){
            seg[p*2]=0;
            seg[p*2+1]=0;
            seg2[p*2]=seg2[p];
            seg2[p*2+1]=seg2[p];
        }
        if(seg[p]){
            seg[p*2]+=seg[p];
            seg[p*2+1]+=seg[p];
            seg[p]=0;
        }
    }
    else{
        if(seg2[p]==1){
            seg[p]+=vec[s].first;
        }
        if(seg2[p]==-1){
            seg[p]+=0;
        }
    }
    seg2[p]=0;
}
void build(int p,int s,int e)
{
    cout<<p<<" "<<s<<" "<<e<<" "<<seg[p]<<" "<<seg2[p]<<endl;
    if(s==e)return;
    int mid=(s+e)/2;
    build(p*2,s,mid);
    build(p*2+1,mid+1,e);
}
int get(int p,int s,int e,int i)
{
    fix(p,s,e);
    if(s==e){
        return seg[p];
    }
    int mid=(s+e)/2;
    if(i<=mid){
        return get(p*2,s,mid,i);
    }
    else{
        return get(p*2+1,mid+1,e,i);
    }
}
void update1(int p,int s,int e,int a,int b,int v)
{
    fix(p,s,e);
    if(a<=s&&b<=e){
        seg[p]+=v;
        fix(p,s,e);
        return;
    }
    if(s>b||e<a)return;
    int mid=(s+e)/2;
    update1(p*2,s,mid,a,b,v);
    update1(p*2+1,mid+1,e,a,b,v);
}
void update2(int p,int s,int e,int a,int b,int v)
{
    fix(p,s,e);
    if(a<=s&&e<=b){
        seg2[p]=v;
        seg[p]=0;
        fix(p,s,e);
        return;
    }
    if(s>b||e<a)return;
    int mid=(s+e)/2;
    update2(p*2,s,mid,a,b,v);
    update2(p*2+1,mid+1,e,a,b,v);
}
vector<int> distribute_candies(vector<int> c,vector<int> l,
                                    vector<int> r,vector<int> v){

    int n=c.size();
    int m=l.size();
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        vec.push_back({c[i],i});
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    for(int i=0;i<m;i++){
        int l=0,r=n-1,ann=-1;
        while(l<=r){
            int mid=(l+r)/2;
            if(0<=get(1,0,n-1,mid)+v[i]&&get(1,0,n-1,mid)+v[i]<=vec[mid].first){
//                cout<<"mid "<<mid<<" "<<get(1,0,n-1,mid)<<" "<<v[i]<<" "<<vec[i].first<<endl;
                ann=mid;
                l=mid+1;
            }
            else{
                r=mid-1;
            }
        }
        if(ann!=-1)update1(1,0,n-1,0,ann,v[i]);
        if(ann!=n-1){
            if(v[i]>0)update2(1,0,n-1,ann+1,n-1,+1);
            else update2(1,0,n-1,ann+1,n-1,-1);
        }
    /*    cout<<ann<<endl;
        for(int i=0;i<n;i++){
            cout<<get(1,0,n-1,i)<<" ";
        }
        cout<<endl;
//        cout<<endl;
  //      build(1,0,n-1);
    //    cout<<endl;
    */
    }
    for(int i=0;i<vec.size();i++){
        auto x= vec[i];
        ans[x.second]=get(1,0,n-1,i);
    }
    return ans;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:123:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |     for(int i=0;i<vec.size();i++){
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 719 ms 13160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 383 ms 7624 KB Output is correct
4 Correct 94 ms 9748 KB Output is correct
5 Correct 958 ms 16620 KB Output is correct
6 Correct 923 ms 17308 KB Output is correct
7 Correct 846 ms 18000 KB Output is correct
8 Correct 897 ms 16640 KB Output is correct
9 Correct 694 ms 18004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -