Submission #836977

# Submission time Handle Problem Language Result Execution time Memory
836977 2023-08-24T19:03:21 Z il9 Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"
#include <bits/stdc++.h>
vector<array<int,2> > seg(2000001);
vector<bool> segtrue(2000001);
vector<array<int,2> > li;
vector<int> flag(200001);
void build(int v, int tl, int tr){
    if(tl==tr){
        seg[v]=li[tl];
        segtrue[v]=1;
    }else{
        int tm=(tl+tr)/2;
        build(v*2,tl,tm);
        build(v*2+1,tm+1,tr);
    }
}
void push_flag(int v){
    if(flag[v]!=0){
        if(segtrue[v*2]){
            if(flag[v]>0){
                seg[v*2][0]=min(seg[v*2][0]+flag[v],seg[v*2][1]);
            }else{
                seg[v*2][0]=max(seg[v*2][0]+flag[v],0);
            }
        }else if(flag[v*2]>0){
            push_flag(v*2);
            flag[v*2]=flag[v];
        }
        if(segtrue[v*2+1]){
            if(flag[v]>0){
                seg[v*2+1][0]=min(seg[v*2+1][0]+flag[v],seg[v*2+1][1]);
            }else{
                seg[v*2+1][0]=max(seg[v*2+1][0]+flag[v],0);
            }
        }else if(flag[v*2+1]>0){
            push_flag(v*2+1);
            flag[v*2+1]=flag[v];
        }

    }
}
void update(int v, int tl, int tr, int l, int r, int x){
    pushflag(v);
    if(l==tl&&r==tr){
        flag[v]=x;
        return;
    }
}
int query(int v,int tl, int tr, int pos){
    if(tl==tr){
        return seg[v];
    }
    int tm=(tl+tr)/2;
    if(pos<=tm){
        query(v*2,tl,tm,pos);
    }else{
        query(v*2+1,tm+1,tr,pos);
    }
}
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    
    for(int i=0;i<n;i++){
        li.push_back({0,c[i]});
    }
    for(int i=0;i<l.size();i++){
        update(1,0,n-1,l[i],r[i],v[i]);
    }
    vector<int> ans;
    for(int i=0;i<n;i++){
        ans.push_back(query(1,0,n-1,i));
    }
    return ans;
   
}

Compilation message

candies.cpp:3:1: error: 'vector' does not name a type
    3 | vector<array<int,2> > seg(2000001);
      | ^~~~~~
candies.cpp:4:1: error: 'vector' does not name a type
    4 | vector<bool> segtrue(2000001);
      | ^~~~~~
candies.cpp:5:1: error: 'vector' does not name a type
    5 | vector<array<int,2> > li;
      | ^~~~~~
candies.cpp:6:1: error: 'vector' does not name a type
    6 | vector<int> flag(200001);
      | ^~~~~~
candies.cpp: In function 'void build(int, int, int)':
candies.cpp:9:9: error: 'seg' was not declared in this scope
    9 |         seg[v]=li[tl];
      |         ^~~
candies.cpp:9:16: error: 'li' was not declared in this scope
    9 |         seg[v]=li[tl];
      |                ^~
candies.cpp:10:9: error: 'segtrue' was not declared in this scope
   10 |         segtrue[v]=1;
      |         ^~~~~~~
candies.cpp: In function 'void push_flag(int)':
candies.cpp:18:8: error: 'flag' was not declared in this scope
   18 |     if(flag[v]!=0){
      |        ^~~~
candies.cpp:19:12: error: 'segtrue' was not declared in this scope
   19 |         if(segtrue[v*2]){
      |            ^~~~~~~
candies.cpp:21:17: error: 'seg' was not declared in this scope
   21 |                 seg[v*2][0]=min(seg[v*2][0]+flag[v],seg[v*2][1]);
      |                 ^~~
candies.cpp:21:29: error: 'min' was not declared in this scope; did you mean 'std::min'?
   21 |                 seg[v*2][0]=min(seg[v*2][0]+flag[v],seg[v*2][1]);
      |                             ^~~
      |                             std::min
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: 'std::min' declared here
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
candies.cpp:23:17: error: 'seg' was not declared in this scope
   23 |                 seg[v*2][0]=max(seg[v*2][0]+flag[v],0);
      |                 ^~~
candies.cpp:23:29: error: 'max' was not declared in this scope; did you mean 'std::max'?
   23 |                 seg[v*2][0]=max(seg[v*2][0]+flag[v],0);
      |                             ^~~
      |                             std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
candies.cpp:29:12: error: 'segtrue' was not declared in this scope
   29 |         if(segtrue[v*2+1]){
      |            ^~~~~~~
candies.cpp:31:17: error: 'seg' was not declared in this scope
   31 |                 seg[v*2+1][0]=min(seg[v*2+1][0]+flag[v],seg[v*2+1][1]);
      |                 ^~~
candies.cpp:31:31: error: 'min' was not declared in this scope; did you mean 'std::min'?
   31 |                 seg[v*2+1][0]=min(seg[v*2+1][0]+flag[v],seg[v*2+1][1]);
      |                               ^~~
      |                               std::min
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: 'std::min' declared here
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
candies.cpp:33:17: error: 'seg' was not declared in this scope
   33 |                 seg[v*2+1][0]=max(seg[v*2+1][0]+flag[v],0);
      |                 ^~~
candies.cpp:33:31: error: 'max' was not declared in this scope; did you mean 'std::max'?
   33 |                 seg[v*2+1][0]=max(seg[v*2+1][0]+flag[v],0);
      |                               ^~~
      |                               std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
candies.cpp: In function 'void update(int, int, int, int, int, int)':
candies.cpp:43:5: error: 'pushflag' was not declared in this scope; did you mean 'push_flag'?
   43 |     pushflag(v);
      |     ^~~~~~~~
      |     push_flag
candies.cpp:45:9: error: 'flag' was not declared in this scope
   45 |         flag[v]=x;
      |         ^~~~
candies.cpp: In function 'int query(int, int, int, int)':
candies.cpp:51:16: error: 'seg' was not declared in this scope
   51 |         return seg[v];
      |                ^~~
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:65:9: error: 'li' was not declared in this scope; did you mean 'i'?
   65 |         li.push_back({0,c[i]});
      |         ^~
      |         i
candies.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i=0;i<l.size();i++){
      |                 ~^~~~~~~~~
candies.cpp:70:5: error: 'vector' was not declared in this scope
   70 |     vector<int> ans;
      |     ^~~~~~
candies.cpp:70:5: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
candies.cpp:70:12: error: expected primary-expression before 'int'
   70 |     vector<int> ans;
      |            ^~~
candies.cpp:72:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   72 |         ans.push_back(query(1,0,n-1,i));
      |         ^~~
      |         abs
candies.cpp:74:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
   74 |     return ans;
      |            ^~~
      |            abs