Submission #696681

# Submission time Handle Problem Language Result Execution time Memory
696681 2023-02-07T03:36:26 Z Tuanlinh123 Izbori (COCI22_izbori) C++17
40 / 110
49 ms 17560 KB
// #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

#define LOCALIO "C:/Users/admin/Documents/Code/"

ll a[200005], cnt[200005];
vector <ll> num;
map <ll, ll> Map;

struct BIT
{
    ll n;
    vector <ll> bit;

    BIT(ll n): n(n)
    {
        bit.assign(n+1, 0);
    }

    void update(ll i, ll val)
    {
        for (i; i<=n; i+=i&(-i))
            bit[i]+=val;
    }

    ll query(ll l, ll r)
    {
        ll ans=0; l--;
        for (r; r>0; r-=r&(-r))
            ans+=bit[r];
        for (l; l>0; l-=l&(-l))
            ans-=bit[l];
        return ans;
    }
};

int main()
{
    #ifdef LOCAL
        freopen( LOCALIO "input.txt","r",stdin) ;
        freopen( LOCALIO "output.txt","w",stdout) ;
    #endif

    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
//	freopen("FIBONACCI.inp","r",stdin);
//	freopen("FIBONACCI.out","w",stdout);
    ll n; cin >> n;
    ll Max=0;
    for (ll i=1; i<=n; i++)
    {
        cin >> a[i]; Max=max(Max, a[i]);
        if (Map[a[i]]==0)
        {
            num.pb(a[i]);
            Map[a[i]]=1;
        }
    }
    for (ll i=0; i<num.size(); i++)
        Map[num[i]]=i+1;
    for (ll i=1; i<=n; i++)
        a[i]=Map[a[i]];
    if (Max<=2)
    {
        ll ans=0;
        BIT A0(n*5), A1(n*5);
        A0.update(n+1, 1);
        A1.update(n+1, 1);
        ll cnt0=0, cnt1=0;
        for (ll i=1; i<=n; i++)
        {
            cnt0+=a[i]==1;
            cnt1+=a[i]==2;
            ans+=A0.query(1, cnt0*2-i+n);
            ans+=A1.query(1, cnt1*2-i+n);
            // cout << cnt0*2-i+n << " " << cnt1*2-i+n << "\n";
            A0.update(cnt0*2-i+n+1, 1);
            A1.update(cnt1*2-i+n+1, 1);
        // cout << "bruh" << flush;
        }
        cout << ans;
        return 0;
    }
    if (n<=3000)
    {
        ll ans=0;
        for (ll i=1; i<=n; i++)
        {
            ll Max=0;
            for (ll j=1; j<=n; j++)
                cnt[a[j]]=0;
            for (ll j=i; j<=n; j++)
            {
                cnt[a[j]]++;
                Max=max(Max, cnt[a[j]]);
                if (Max>j-i+1-Max)
                    ans++;
            }
        }
        cout << ans;
        return 0;
    }
}

Compilation message

Main.cpp: In member function 'void BIT::update(long long int, long long int)':
Main.cpp:31:14: warning: statement has no effect [-Wunused-value]
   31 |         for (i; i<=n; i+=i&(-i))
      |              ^
Main.cpp: In member function 'long long int BIT::query(long long int, long long int)':
Main.cpp:38:14: warning: statement has no effect [-Wunused-value]
   38 |         for (r; r>0; r-=r&(-r))
      |              ^
Main.cpp:40:14: warning: statement has no effect [-Wunused-value]
   40 |         for (l; l>0; l-=l&(-l))
      |              ^
Main.cpp: In function 'int main()':
Main.cpp:67:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (ll i=0; i<num.size(); i++)
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 17 ms 352 KB Output is correct
10 Correct 10 ms 340 KB Output is correct
11 Correct 17 ms 340 KB Output is correct
12 Correct 16 ms 340 KB Output is correct
13 Correct 16 ms 340 KB Output is correct
14 Correct 16 ms 340 KB Output is correct
15 Correct 16 ms 344 KB Output is correct
16 Correct 13 ms 340 KB Output is correct
17 Correct 16 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 11852 KB Output is correct
2 Correct 42 ms 15288 KB Output is correct
3 Correct 20 ms 9040 KB Output is correct
4 Correct 44 ms 15964 KB Output is correct
5 Correct 43 ms 16468 KB Output is correct
6 Correct 46 ms 17484 KB Output is correct
7 Correct 49 ms 17492 KB Output is correct
8 Correct 49 ms 17544 KB Output is correct
9 Correct 46 ms 17492 KB Output is correct
10 Correct 39 ms 17420 KB Output is correct
11 Correct 40 ms 17560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 17 ms 352 KB Output is correct
10 Correct 10 ms 340 KB Output is correct
11 Correct 17 ms 340 KB Output is correct
12 Correct 16 ms 340 KB Output is correct
13 Correct 16 ms 340 KB Output is correct
14 Correct 16 ms 340 KB Output is correct
15 Correct 16 ms 344 KB Output is correct
16 Correct 13 ms 340 KB Output is correct
17 Correct 16 ms 340 KB Output is correct
18 Correct 33 ms 11852 KB Output is correct
19 Correct 42 ms 15288 KB Output is correct
20 Correct 20 ms 9040 KB Output is correct
21 Correct 44 ms 15964 KB Output is correct
22 Correct 43 ms 16468 KB Output is correct
23 Correct 46 ms 17484 KB Output is correct
24 Correct 49 ms 17492 KB Output is correct
25 Correct 49 ms 17544 KB Output is correct
26 Correct 46 ms 17492 KB Output is correct
27 Correct 39 ms 17420 KB Output is correct
28 Correct 40 ms 17560 KB Output is correct
29 Incorrect 18 ms 1876 KB Output isn't correct
30 Halted 0 ms 0 KB -