Submission #1314377

#TimeUsernameProblemLanguageResultExecution timeMemory
1314377thuhienne가로등 (APIO19_street_lamps)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define thuhien "" #define re exit(0); int n,q; string s; bool state[maxn]; struct Fenwick2D { vector <int> index,value; } fenwick; set <pair <int,int>> segment; struct qu { char op;int a,b; } query[maxn]; int main() { // ios_base::sync_with_stdio(0); // cin.tie(nullptr); if (fopen(thuhien".inp","r")) { freopen(thuhien".inp","r",stdin); freopen(thuhien".out","w",stdout); } cin >> n >> q >> s; s = " " + s; int last = -1; for (int i = 1;i <= n;i++) { state[i] = s[i] - '0'; if (s[i] == '0') { if (last != -1) segment.insert(make_pair(last,i - 1)); last = -1; } else { if (last == -1) last = i; } } if (last != -1) segment.insert(make_pair(last,i - 1)); for (int i = 1;i <= q;i++) { string TMP;cin >> TMP >> query[i].a; query[i].op = TMP[0]; if (query[i].op == 'q') { cin >> query[i].b; query[i].b--; } else { int pos = query[i].a; if (state[pos]) { auto it = segment.upper_bound(make_pair(pos,1e9)); it--; int l = it -> first,r = it -> second; fenwick.event(l,pos,pos,r); segment.erase(it); if (l < pos) segment.insert(make_pair(l,pos - 1)); if (r > pos) segment.insert(make_pair(pos + 1,r)); } else { int l = pos,r = pos; if (state[pos - 1]) { auto it = segment.upper_bound(make_pair(pos,-1)); it--; l = it -> first; } if (state[pos + 1]) { auto it = segment.lower_bound(make_pair(pos + 1,-1)); r = it -> second; } fenwick.event(l,pos,pos,r); } state[pos] ^= 1; } } fen.build(); segment.clear(); last = -1; for (int i = 1;i <= n;i++) { state[i] = s[i] - '0'; if (s[i] == '0') { if (last != -1) segment.insert(make_pair(last,i - 1)); last = -1; } else { if (last == -1) last = i; } } if (last != -1) segment.insert(make_pair(last,i - 1)); for (int i = 1;i <= q;i++) { if (query[i].op == 'q') { cout << fenwick.get(query[i].a,query[i].b) << '\n'; } else { int pos = query[i].a; if (state[pos]) { auto it = segment.upper_bound(make_pair(pos,1e9)); it--; int l = it -> first,r = it -> second; fenwick.update(l,pos,pos,r,i); segment.erase(it); if (l < pos) segment.insert(make_pair(l,pos - 1)); if (r > pos) segment.insert(make_pair(pos + 1,r)); } else { int l = pos,r = pos; if (state[pos - 1]) { auto it = segment.upper_bound(make_pair(pos,-1)); it--; l = it -> first; } if (state[pos + 1]) { auto it = segment.lower_bound(make_pair(pos + 1,-1)); r = it -> second; } fenwick.update(l,pos,pos,r,-i); } state[pos] ^= 1; } } }

Compilation message (stderr)

street_lamps.cpp:12:12: error: 'maxn' was not declared in this scope
   12 | bool state[maxn];
      |            ^~~~
street_lamps.cpp:22:9: error: 'maxn' was not declared in this scope
   22 | } query[maxn];
      |         ^~~~
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:37:17: error: 'state' was not declared in this scope; did you mean '_xstate'?
   37 |                 state[i] = s[i] - '0';
      |                 ^~~~~
      |                 _xstate
street_lamps.cpp:46:55: error: 'i' was not declared in this scope
   46 |         if (last != -1) segment.insert(make_pair(last,i - 1));
      |                                                       ^
street_lamps.cpp:49:42: error: 'query' was not declared in this scope
   49 |                 string TMP;cin >> TMP >> query[i].a;
      |                                          ^~~~~
street_lamps.cpp:58:29: error: 'state' was not declared in this scope; did you mean '_xstate'?
   58 |                         if (state[pos]) {
      |                             ^~~~~
      |                             _xstate
street_lamps.cpp:64:41: error: 'struct Fenwick2D' has no member named 'event'
   64 |                                 fenwick.event(l,pos,pos,r);
      |                                         ^~~~~
street_lamps.cpp:85:41: error: 'struct Fenwick2D' has no member named 'event'
   85 |                                 fenwick.event(l,pos,pos,r);
      |                                         ^~~~~
street_lamps.cpp:90:25: error: 'state' was not declared in this scope; did you mean '_xstate'?
   90 |                         state[pos] ^= 1;
      |                         ^~~~~
      |                         _xstate
street_lamps.cpp:95:9: error: 'fen' was not declared in this scope
   95 |         fen.build();
      |         ^~~
street_lamps.cpp:101:17: error: 'state' was not declared in this scope; did you mean '_xstate'?
  101 |                 state[i] = s[i] - '0';
      |                 ^~~~~
      |                 _xstate
street_lamps.cpp:111:55: error: 'i' was not declared in this scope
  111 |         if (last != -1) segment.insert(make_pair(last,i - 1));
      |                                                       ^
street_lamps.cpp:115:21: error: 'query' was not declared in this scope
  115 |                 if (query[i].op == 'q') {
      |                     ^~~~~
street_lamps.cpp:117:41: error: 'struct Fenwick2D' has no member named 'get'
  117 |                         cout << fenwick.get(query[i].a,query[i].b) << '\n';
      |                                         ^~~
street_lamps.cpp:122:29: error: 'state' was not declared in this scope; did you mean '_xstate'?
  122 |                         if (state[pos]) {
      |                             ^~~~~
      |                             _xstate
street_lamps.cpp:128:41: error: 'struct Fenwick2D' has no member named 'update'
  128 |                                 fenwick.update(l,pos,pos,r,i);
      |                                         ^~~~~~
street_lamps.cpp:149:41: error: 'struct Fenwick2D' has no member named 'update'
  149 |                                 fenwick.update(l,pos,pos,r,-i);
      |                                         ^~~~~~
street_lamps.cpp:154:25: error: 'state' was not declared in this scope; did you mean '_xstate'?
  154 |                         state[pos] ^= 1;
      |                         ^~~~~
      |                         _xstate
street_lamps.cpp:28:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |            freopen(thuhien".inp","r",stdin);
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:29:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |            freopen(thuhien".out","w",stdout);
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~