답안 #392317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392317 2021-04-20T19:21:03 Z MiricaMatei Worst Reporter 4 (JOI21_worst_reporter4) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;
const int inf = 2000000000;

struct slope_trick {
  map<int, long long> delta;

  slope_trick () {
    delta = map<int, long long>();
  }

  void mergeDelta(slope_trick other) {
    for (auto it:other.delta)
      delta[it.first] += it.second;
    other.delta.clear();
  }

  void add(int x, long long val) {
    delta[-inf] += val;
    delta[x] -= val;
    delta[x + 1] += val;

    map<int, long long>::iterator it1, it2;
    it1 = delta.lower_bound(x);

    val = delta[x];
    while (val <= 0) {
      if (it1 -- delta.begin())
        exit(0);
      it2 = it1;
      it1--;
      delta.erase(it2);
      val = it1->second + val;
      it1->second = val;
    }
  }
    int mapSize() {
      return delta.size();
    }

    long long query() {
      return delta[-inf];
    }
};

vector<int>G[MAXN];

int a[MAXN], h[MAXN], c[MAXN];

slope_trick dfs(int node) {
  slope_trick ans;
  for (auto it:G[node]) {
    slope_trick aux = dfs(it);
    if (aux.mapSize() > ans.mapSize())
      swap(ans, aux);
    ans.mergeDelta(aux);
  }
  ans.add(h[node], c[node]);
  return ans;
}

long long solve(int node) {
  slope_trick ans = dfs(node);
  return ans.query();
}

int main() {
  //freopen("date.in", "r", stdin);
  //freopen("date.out", "w", stdout);

  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d%d%d", &a[i], &h[i], &c[i]);
    if (i > 1)
      G[a[i]].push_back(i);
  }

  long long ans = solve(1);

  printf("%lld\n", ans);

  return 0;
}

Compilation message

worst_reporter2.cpp: In member function 'void slope_trick::add(int, long long int)':
worst_reporter2.cpp:31:17: error: expected ')' before 'delta'
   31 |       if (it1 -- delta.begin())
      |          ~      ^~~~~~
      |                 )
worst_reporter2.cpp:31:15: error: could not convert 'it1.std::_Rb_tree_iterator<std::pair<const int, long long int> >::operator--(0)' from 'std::_Rb_tree_iterator<std::pair<const int, long long int> >::_Self' {aka 'std::_Rb_tree_iterator<std::pair<const int, long long int> >'} to 'bool'
   31 |       if (it1 -- delta.begin())
      |           ~~~~^~
      |               |
      |               std::_Rb_tree_iterator<std::pair<const int, long long int> >::_Self {aka std::_Rb_tree_iterator<std::pair<const int, long long int> >}
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |   scanf("%d", &N);
      |   ~~~~~^~~~~~~~~~
worst_reporter2.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   77 |     scanf("%d%d%d", &a[i], &h[i], &c[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~