Submission #893312

# Submission time Handle Problem Language Result Execution time Memory
893312 2023-12-26T22:44:40 Z vjudge1 Izbori (COCI22_izbori) C++17
40 / 110
3000 ms 40988 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
const int N=2e5+5;
int n,arr[N];
ll solve(int l,int r){
    if(l>r){
        return 0;
    }
    if(l==r){
        return 1;
    }
    int mid=l+r>>1;
    ll ret=0;
    set<int>s;
    map<int,int>fr;
    for(int i=l;i<=r;i++){
        s.insert(arr[i]);
    }
    for(auto x:s){// atmost log n numbers
        fr.clear();
        int prefix=0;
        fr[prefix]++;
        for(int i=l;i<mid;i++){
            prefix+=(arr[i]==x?1:-1);
            fr[prefix]++;
        }
        int sz=(r-l+1);
        for(int i=-sz;i<=sz;i++){
            fr[i]+=fr[i-1];
        }
        for(int i=mid;i<=r;i++){
            prefix+=(arr[i]==x?1:-1);
            ret+=fr[prefix-1];
        }
    }
    return ret+solve(l,mid-1)+solve(mid+1,r);
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #ifndef ONLINE_JUDGE
  //  freopen("input.in", "r", stdin);
  //  freopen("output.out", "w", stdout);
    #endif
    fast
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    cout<<solve(0,n-1)<<endl;
    return 0;
}

Compilation message

Main.cpp: In function 'll solve(int, int)':
Main.cpp:47:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |     int mid=l+r>>1;
      |             ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 302 ms 604 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 40 ms 860 KB Output is correct
10 Correct 33 ms 856 KB Output is correct
11 Correct 38 ms 860 KB Output is correct
12 Correct 34 ms 856 KB Output is correct
13 Correct 33 ms 860 KB Output is correct
14 Correct 33 ms 860 KB Output is correct
15 Correct 37 ms 856 KB Output is correct
16 Correct 39 ms 860 KB Output is correct
17 Correct 5 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 995 ms 26196 KB Output is correct
2 Correct 1341 ms 34124 KB Output is correct
3 Correct 781 ms 20052 KB Output is correct
4 Correct 1410 ms 35700 KB Output is correct
5 Correct 1482 ms 36988 KB Output is correct
6 Correct 1569 ms 39624 KB Output is correct
7 Correct 1554 ms 39248 KB Output is correct
8 Correct 1587 ms 39196 KB Output is correct
9 Correct 1605 ms 39312 KB Output is correct
10 Correct 1580 ms 39248 KB Output is correct
11 Correct 952 ms 39248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 302 ms 604 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 40 ms 860 KB Output is correct
10 Correct 33 ms 856 KB Output is correct
11 Correct 38 ms 860 KB Output is correct
12 Correct 34 ms 856 KB Output is correct
13 Correct 33 ms 860 KB Output is correct
14 Correct 33 ms 860 KB Output is correct
15 Correct 37 ms 856 KB Output is correct
16 Correct 39 ms 860 KB Output is correct
17 Correct 5 ms 860 KB Output is correct
18 Correct 995 ms 26196 KB Output is correct
19 Correct 1341 ms 34124 KB Output is correct
20 Correct 781 ms 20052 KB Output is correct
21 Correct 1410 ms 35700 KB Output is correct
22 Correct 1482 ms 36988 KB Output is correct
23 Correct 1569 ms 39624 KB Output is correct
24 Correct 1554 ms 39248 KB Output is correct
25 Correct 1587 ms 39196 KB Output is correct
26 Correct 1605 ms 39312 KB Output is correct
27 Correct 1580 ms 39248 KB Output is correct
28 Correct 952 ms 39248 KB Output is correct
29 Correct 955 ms 40988 KB Output is correct
30 Execution timed out 3019 ms 5976 KB Time limit exceeded
31 Halted 0 ms 0 KB -