Submission #937080

# Submission time Handle Problem Language Result Execution time Memory
937080 2024-03-03T12:25:35 Z LOLOLO Street Lamps (APIO19_street_lamps) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 3e5 + 100;
 
struct fen{
    const int N = 1e6 + 10;
    vector <ll> f;
 
    fen() {
        f.assign(N, 0);
    }
 
    void upd(int i, ll x) {
        for (; i < N; i += i & (-i))
            f[i] += x;
    }
 
    ll get(int i) {
        ll s = 0;
        for (; i; i -= i & (-i))
            s += f[i];
 
        return s;
    }
};
 
fen fsum, fnum;
vector < vector <int>> all;
ll ans[N];
 
bool cmp(vector <int>&a, vector <int>&b) {
    if (a[0] == b[0]) {
        return a.back() > b.back();
    }
 
    return a[0] > b[0];
}
 
void dnc(int l, int r) {
    if (l == r)
        return;
 
    int m = (l + r) / 2;
    dnc(l, m);
    dnc(m + 1, r);
 
    vector < vector <int>> save;
    for (int i = l; i <= m; i++) {
        if (all[i].back() == 1) {
            save.pb({all[i][1], all[i][2], all[i][3]});
        }
    }
 
    for (int i = m + 1; i <= r; i++) {
        if (all[i].back() == 0) {
            save.pb({all[i][1], all[i][2], all[i][3]});
        }
    }
 
    sort(all(save), cmp);
    for (auto x : save) {
        if (x.back() == 1) {
            fsum.upd(abs(x[1]), x[1]);
            if (x[1] >= 0) {
                fnum.upd(abs(x[1]), 1);
            } else {
                fnum.upd(abs(x[1]), -1);
            }
        } else {
            ll cur = fsum.get(x[1]);
            if (fnum.get(x[1]) != 0) {
                cur += x[1];
            }
 
            ans[x[1]] += cur;
        }
    }
 
    for (auto x : save) {
        if (x.back() == 1) {
            fsum.upd(abs(x[1]), -x[1]);
            if (x[1] >= 0) {
                fnum.upd(abs(x[1]), -1);
            } else {
                fnum.upd(abs(x[1]), 1);
            }
        } 
    }
}
 
bool is[N];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int n, q;
    cin >> n >> q;
 
    string s;
    cin >> s;
    s = "0" + s + "0";
 
    set <int> st;
    
    for (int i = 0; i < len(s); i++) {
        if (s[i] == '0') {
            if (i) {
                int p = *(--st.end()) + 1;
                if (p <= i - 1) {
                    all.pb({p, i - 1, -1, 1});
                }
            }
            st.insert(i);
        }
    }
 
    for (int i = 1; i <= q; i++) {
        string t;
        cin >> t;
 
        if (t[0] == 't') {
            int p;
            cin >> p;
 
            if (s[p] == '0') {
                st.erase(p);
                s[p] = '1';
                auto it = st.lower_bound(p);
                int r = (*it) - 1, l = (*prev(it)) + 1;
                all.pb({l, r, -i - 1, 1});
 
                if (p - 1 >= l) {
                    all.pb({l, p - 1, i + 1, 1});
                }
 
                if (p + 1 <= r) {
                    all.pb({p + 1, r, i + 1, 1});
                }
            } else {
                auto it = st.lower_bound(p);
                int r = (*it) - 1, l = (*prev(it)) + 1;
                all.pb({l, r, i + 1, 1});
 
                if (p - 1 >= l) {
                    all.pb({l, p - 1, -i - 1, 1});
                }
 
                if (p + 1 <= r) {
                    all.pb({p + 1, r, -i - 1, 1});
                }
 
                s[p] = '0';
                st.insert(p);
            }
        } else {
            is[i] = 1;
            int a, b;
            cin >> a >> b;
            all.pb({a, b - 1, i + 1, 0});
        }
    }
 
    sort(all(all), [&](vector <int> &a, vector <int> &b) {return a[0] == b[0] ? a.back() > b.back() : a[0] < b[0];});
    dnc(0, sz(all) - 1);
 
    for (int i = 1; i <= q; i++) {
        if (is[i] == 1) {
            cout << ans[i] << '\n';
        }
    }
}

Compilation message

street_lamps.cpp:92:2: error: extended character   is not valid in an identifier
   92 |                 cur += x[1];
      |  ^
street_lamps.cpp:92:5: error: extended character   is not valid in an identifier
   92 |                 cur += x[1];
      |    ^
street_lamps.cpp:92:8: error: extended character   is not valid in an identifier
   92 |                 cur += x[1];
      |      ^
street_lamps.cpp:92:11: error: extended character   is not valid in an identifier
   92 |                 cur += x[1];
      |        ^
street_lamps.cpp:92:14: error: extended character   is not valid in an identifier
   92 |                 cur += x[1];
      |          ^
street_lamps.cpp:92:17: error: extended character   is not valid in an identifier
   92 |                 cur += x[1];
      |            ^
street_lamps.cpp:92:20: error: extended character   is not valid in an identifier
   92 |                 cur += x[1];
      |              ^
street_lamps.cpp:92:23: error: extended character   is not valid in an identifier
   92 |                 cur += x[1];
      |                ^
street_lamps.cpp:181:2: error: extended character   is not valid in an identifier
  181 |             all.pb({a, b - 1, i + 1, 0});
      |  ^
street_lamps.cpp:181:5: error: extended character   is not valid in an identifier
  181 |             all.pb({a, b - 1, i + 1, 0});
      |    ^
street_lamps.cpp:181:8: error: extended character   is not valid in an identifier
  181 |             all.pb({a, b - 1, i + 1, 0});
      |      ^
street_lamps.cpp:181:11: error: extended character   is not valid in an identifier
  181 |             all.pb({a, b - 1, i + 1, 0});
      |        ^
street_lamps.cpp:181:14: error: extended character   is not valid in an identifier
  181 |             all.pb({a, b - 1, i + 1, 0});
      |          ^
street_lamps.cpp:181:17: error: extended character   is not valid in an identifier
  181 |             all.pb({a, b - 1, i + 1, 0});
      |            ^
street_lamps.cpp: In function 'void dnc(int, int)':
street_lamps.cpp:92:2: error: '\U000000a0' was not declared in this scope
   92 |                 cur += x[1];
      |  ^
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:181:2: error: '\U000000a0' was not declared in this scope
  181 |             all.pb({a, b - 1, i + 1, 0});
      |  ^
street_lamps.cpp:181:46: error: expected primary-expression before ')' token
  181 |             all.pb({a, b - 1, i + 1, 0});
      |                                        ^