Submission #1048136

# Submission time Handle Problem Language Result Execution time Memory
1048136 2024-08-08T00:52:43 Z vjudge1 Distributing Candies (IOI21_candies) C++17
29 / 100
400 ms 23240 KB
#include "candies.h"

#include<bits/stdc++.h>
using namespace std;
int CONS, Kof[200100];
vector<int>ans;
struct segtree{
    struct DATA{
        int extreme,dif;
        DATA(){
            extreme=0;
            dif=0;
        }
        DATA(int a,int b){
            extreme=a,dif=b;
        }
        void apply(DATA k){
            if(k.extreme)
                extreme=k.extreme,dif=0;
            dif+=k.dif;
        }
        int q(int K){
            return (extreme>0)*K+dif;
        }
    } T[1<<19];
    void pd(int i){
        T[i*2].apply(T[i]);
        T[i*2+1].apply(T[i]);
        T[i]=DATA();
    }
    void Add(int i,int l,int r,int ll,int rr,int v){
        if(ll<=l&&r<=rr)
            return T[i].apply((DATA){0,v});
        if(ll>r||l>rr) return;
        pd(i);Add(i*2,l,l+r>>1,ll,rr,v);
        Add(i*2+1,l+r+2>>1,r,ll,rr,v);
    }
    void Set(int i,int l,int r,int ll,int rr,int v){
        if(ll<=l&&r<=rr)
            return T[i].apply((DATA){v,0});
        if(ll>r||l>rr) return;
        pd(i);Set(i*2,l,l+r>>1,ll,rr,v);
        Set(i*2+1,l+r+2>>1,r,ll,rr,v);
    }
    int Qry(int i,int l,int r,int p){
        if(l==r) return T[i].q(Kof[l]);
        pd(i);if(l+r>>1>=p)
            return Qry(i*2,l,l+r>>1,p);
        return Qry(i*2+1,l+r+2>>1,r,p);
    }
} seg;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    map<int,int>mp;
    for(auto i:c)
        mp[i];
    int CC=0;
    for(auto&[i,j]:mp)
        Kof[j=++CC]=i;
    CONS=c[0]; 
    int n = c.size(),q=l.size();
    seg.T[1].extreme=-1;
    for(int i=0;i<q;i++) {
        int l=1,r=CC,res=0;
        while(l<=r){
            int mid=l+r>>1;
            int K=seg.Qry(1,1,CC,mid);
            if(v[i]<0){
                if(K<-v[i])
                    l=mid+1,res=mid;
                else r=mid-1;
            } else {
                if(v[i]>Kof[mid]-K)
                    l=mid+1,res=mid;
                else r=mid-1;
            }
        }
        seg.Set(1,1,CC,1,res,v[i]<0?-1:1);
        seg.Add(1,1,CC,res+1,CC,v[i]);
    }
    for(int i=0;i<n;i++)
        ans.push_back(seg.Qry(1,1,CC,mp[c[i]]));
    return ans;
}

Compilation message

candies.cpp: In member function 'void segtree::Add(int, int, int, int, int, int)':
candies.cpp:35:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |         pd(i);Add(i*2,l,l+r>>1,ll,rr,v);
      |                         ~^~
candies.cpp:36:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         Add(i*2+1,l+r+2>>1,r,ll,rr,v);
      |                   ~~~^~
candies.cpp: In member function 'void segtree::Set(int, int, int, int, int, int)':
candies.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |         pd(i);Set(i*2,l,l+r>>1,ll,rr,v);
      |                         ~^~
candies.cpp:43:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |         Set(i*2+1,l+r+2>>1,r,ll,rr,v);
      |                   ~~~^~
candies.cpp: In member function 'int segtree::Qry(int, int, int, int)':
candies.cpp:47:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         pd(i);if(l+r>>1>=p)
      |                  ~^~
candies.cpp:48:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |             return Qry(i*2,l,l+r>>1,p);
      |                              ~^~
candies.cpp:49:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |         return Qry(i*2+1,l+r+2>>1,r,p);
      |                          ~~~^~
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:66:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |             int mid=l+r>>1;
      |                     ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Incorrect 1 ms 4700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 262 ms 18212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 110 ms 9508 KB Output is correct
4 Correct 107 ms 13812 KB Output is correct
5 Correct 307 ms 16840 KB Output is correct
6 Correct 400 ms 22384 KB Output is correct
7 Correct 366 ms 23240 KB Output is correct
8 Correct 289 ms 20164 KB Output is correct
9 Correct 54 ms 17352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Incorrect 1 ms 4700 KB Output isn't correct
3 Halted 0 ms 0 KB -