제출 #229842

#제출 시각아이디문제언어결과실행 시간메모리
229842frodakcinEditor (BOI15_edi)C++11
컴파일 에러
0 ms0 KiB
#include <cstdio> #include <vector> #include <set> struct upd { public: int t, l; bool operator < (upd o) const {return l > o.l || !(o.l > l) && t < o.t;} }; const int MN = 3e5 + 100; int N, a[MN], f[MN], B; upd b[MN]; std::set<int> c, h; bool d[MN], g[MN]; std::vector<int> e[MN]; void dfs(int n, int v) { f[n] = v; for(int x:e[n]) dfs(x, v); } int main(void) { scanf("%d", &N); for(int i=1;i<=N;++i) scanf("%d", a+i); for(int i=1;i<=N;++i) { if(a[i]<0) b[B++] = {i, -a[i]}; c.insert(i); } std::sort(b, b+B); for(int i=0;i<B;++i) { //printf("B VALS: %d %d\n", b[i].t, b[i].l); auto v = c.lower_bound(b[i].t); assert(v != c.begin()); if(d[b[i].t]) e[*--v].push_back(b[i].t); else { e[*--v].push_back(b[i].t); d[*v] = d[b[i].t] = 1; c.erase(c.erase(v)); } } for(int i=1;i<=N;++i) if(a[i]>=0) dfs(i, i); h.insert(0); for(int i=1;i<=N;++i) { if(g[f[i]]) h.erase(f[i]); else h.insert(f[i]); g[f[i]]^=1; printf("%d\n", a[*std::prev(h.end())]); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

edi.cpp: In member function 'bool upd::operator<(upd) const':
edi.cpp:9:62: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  bool operator < (upd o) const {return l > o.l || !(o.l > l) && t < o.t;}
                                                   ~~~~~~~~~~~^~~~~~~~~~
edi.cpp: In function 'int main()':
edi.cpp:34:7: error: 'sort' is not a member of 'std'
  std::sort(b, b+B);
       ^~~~
edi.cpp:34:7: note: suggested alternative: 'set'
  std::sort(b, b+B);
       ^~~~
       set
edi.cpp:39:3: error: 'assert' was not declared in this scope
   assert(v != c.begin());
   ^~~~~~
edi.cpp:39:3: note: suggested alternative: 'short'
   assert(v != c.begin());
   ^~~~~~
   short
edi.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
edi.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a+i);
   ~~~~~^~~~~~~~~~~