Submission #522876

# Submission time Handle Problem Language Result Execution time Memory
522876 2022-02-06T08:36:43 Z Cross_Ratio Monochrome Points (JOI20_monochrome) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx2")
using namespace std;
struct SegTree {
    vector<int> seg;
    int MAX;
    void init(int N) {
        seg.resize(N+5);
        MAX = N+5;
    }
    void clear() {
        fill(seg.begin(),seg.end(),0);
    }
    int sum(int i) {
        int ans = 0;
        while(i>0) {
            //cout << i << ' ' << ans << '\n';
            ans += seg[i];
            i -= (i&-i);
        }
        return ans;
    }
    void Edit(int i, int a) {
        i++;
        while(i<MAX) {
            //cout << i << '\n';
            seg[i] += a;
            i += (i & -i);
        }
    }
    int sum(int s, int e) {
        return sum(e)-sum(s);
    }
};
SegTree tree;
int used[200005]
int simulate(vector<int> V) {
    //cout << "simul\n";
    tree.clear();
    fill(used,used+V.size()/2,-1);
    int ans = 0;
    int i;
    for(i=0;i<V.size();i++) {
        if(used[V[i]] != -1) {
            ans += tree.sum(used[V[i]]+1, i);
            tree.Edit(used[V[i]],-1);
        }
        else {
            tree.Edit(i, 1);
            used[V[i]] = i;
        }
    }
    return ans;
}
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N;
    string s2;
    cin >> N >> s2;
    tree.init(2*N);
    int i, j, k;
    vector<int> A, B;
    for(i=0;i<2*N;i++) {
        if(s2[i]=='B') A.push_back(i);
        else B.push_back(i);
    }
    vector<int> V;
    V.resize(s2.length());
    for(i=0;i<A.size();i++) V[A[i]] = i;
    int ans = -1;
    int s = 0, e = N - 1;
    while(e-s>=3) {
        int l = (2*s+e)/3;
        int r = (s+2*e)/3;
        for(int j = l; j < l + N; j++) {
            V[B[j%N]] = j-l;
        }
        int v1 = simulate(V);
        for(int j = r; j < r + N; j++) {
            V[B[j%N]] = j-r;
        }
        int v2 = simulate(V);
        if(v1<v2) s = l;
        else e = r;
    }
    for(i=s;i<=e;i++) {
        for(int j = i; j < i + N; j++) {
            V[B[j%N]] = j-i;
        }
        ans = max(ans, simulate(V));
    }
    cout << ans;
}

Compilation message

monochrome.cpp:40:1: error: expected initializer before 'int'
   40 | int simulate(vector<int> V) {
      | ^~~
monochrome.cpp: In function 'int main()':
monochrome.cpp:74:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for(i=0;i<A.size();i++) V[A[i]] = i;
      |             ~^~~~~~~~~
monochrome.cpp:83:18: error: 'simulate' was not declared in this scope
   83 |         int v1 = simulate(V);
      |                  ^~~~~~~~
monochrome.cpp:95:24: error: 'simulate' was not declared in this scope
   95 |         ans = max(ans, simulate(V));
      |                        ^~~~~~~~
monochrome.cpp:66:12: warning: unused variable 'j' [-Wunused-variable]
   66 |     int i, j, k;
      |            ^
monochrome.cpp:66:15: warning: unused variable 'k' [-Wunused-variable]
   66 |     int i, j, k;
      |               ^