Submission #1134972

#TimeUsernameProblemLanguageResultExecution timeMemory
1134972orzdraiduwuSum Zero (RMI20_sumzero)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
// using pr = array<int, 4>;
using pr = array<int, 2>;

// we do binary lifting on the intervals, it's heavy implementation
// so i'll wa this to submit later :sob:
signed main() {
  int n; cin >> n;
  vector<int> v(n);
  for(int i = 0 ; i < n ; i++) {
    int x; cin >> x;
    // c += x;
    v[i] = x;
  }

  unordered_map<int, int> gg;
  vector<pr> uwu;
  int c = 0;
  for(int i = 0 ; i < n ; i++) {
    // if(v[i] == 0) uwu.push_back({i, i});
    // else if(gg.contains(v[i])) uwu.push_back({gg[v[i]], i});
    // gg[v[i]] = i;
    c += v[i];
    if(c == 0) uwu.push_back({0, i});
    else if(gg.contains(c)) uwu.push_back({gg[c]+1, i});
    gg[c] = i;
  }

  // dbg
  // int k = uwu.size();
  // for(int i = 0 ; i < k ; i++) {
  //   cout << uwu[i][0] << " " << uwu[i][1] << endl;
  // }
  // building the graph.
  vector<int> gr(k);
  vector<bool> vis(k);
  unoredered_set<int> gg;
  for(int i = 0 ; i < k ; i++) gr[i] = i;
  sort(uwu.begin(), uwu.end(), [](pr a, pr b) {return a[1] < b[1];});
  for(int i = 0 ; i < k ; i++) {
    if(vis[i]) continue;
    vector<int> del;
    int m = uwu[i][1], ind = i;
    for(auto it = gg.begin() ; it != gg.end() ; it++) {
      int qq = (*it)[0], pp = (*it)[1];
      if(m <= qq) {
        m = pp;
        del.push_back(ind);
        gr[ind] = *it;
        vis[ind] = 1;
        ind = *it;
      }
    }

    for(int c: del) gg.erase(c);
  }

  for(int i = 0 ; i < n ; i++) cout << gr[i] << ' ';
}

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:38:18: error: 'k' was not declared in this scope
   38 |   vector<int> gr(k);
      |                  ^
sumzero.cpp:40:3: error: 'unoredered_set' was not declared in this scope
   40 |   unoredered_set<int> gg;
      |   ^~~~~~~~~~~~~~
sumzero.cpp:4:13: error: expected primary-expression before 'long'
    4 | #define int long long
      |             ^~~~
sumzero.cpp:40:18: note: in expansion of macro 'int'
   40 |   unoredered_set<int> gg;
      |                  ^~~
sumzero.cpp:48:21: error: no match for 'operator[]' (operand types are 'std::pair<const long long int, long long int>' and 'int')
   48 |       int qq = (*it)[0], pp = (*it)[1];
      |                     ^
sumzero.cpp:50:13: error: 'pp' was not declared in this scope; did you mean 'pr'?
   50 |         m = pp;
      |             ^~
      |             pr
sumzero.cpp:52:19: error: cannot convert 'std::pair<const long long int, long long int>' to '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} in assignment
   52 |         gr[ind] = *it;
      |                   ^~~
      |                   |
      |                   std::pair<const long long int, long long int>
sumzero.cpp:54:15: error: cannot convert 'std::pair<const long long int, long long int>' to 'long long int' in assignment
   54 |         ind = *it;
      |               ^~~
      |               |
      |               std::pair<const long long int, long long int>