Submission #964812

# Submission time Handle Problem Language Result Execution time Memory
964812 2024-04-17T15:29:41 Z Ahmed57 Teams (IOI15_teams) C++17
0 / 100
424 ms 95504 KB
#include "bits/stdc++.h"
using namespace std;
int NODES = 0;
int L[3000001],R[3000001],ST[3000001];
int newleaf(int val){
    NODES++;
    L[NODES] = -1;
    R[NODES] = -1;
    ST[NODES] = val;
    return NODES;
}
int newparent(int l,int r){
    NODES++;
    L[NODES] = l;
    R[NODES] = r;
    ST[NODES] = ST[l]+ST[r];
    return NODES;
}
int build(int l,int r){
    if(l==r)return newleaf(0);
    int md = (l+r)/2;
    return newparent(build(l,md),build(md+1,r));
}
int update(int p,int l,int r,int idx){
    if(l==r)return newleaf(1+ST[p]);
    int md = (l+r)/2;
    if(idx<=md)return newparent(update(L[p],l,md,idx),R[p]);
    else return newparent(L[p],update(R[p],md+1,r,idx));
}
int query(int p1,int p2,int l,int r,int lq,int rq){
    if(l>=lq&&r<=rq){
        return ST[p2]-ST[p1];
    }
    if(r<lq||l>rq)return 0;
    int md = (l+r)/2;
    return query(L[p1],L[p2],l,md,lq,rq)+query(R[p1],R[p2],md+1,r,lq,rq);
}
int root[100001],n;
vector<pair<int,int>> v;
void init(int N,int A[],int B[]){
    n = N;
    for(int i = 0;i<N;i++){
        v.push_back({A[i],B[i]});
    }
    sort(v.begin(),v.end());
    root[0] = build(1,n);
    for(int i = 1;i<=v.size();i++){
        root[i] = update(root[i-1],1,n,v[i-1].second);
    }
}
int w(int a,int b){
    int it = lower_bound(v.begin(),v.end(),make_pair(a+1,0))-v.begin();
    int it2 = lower_bound(v.begin(),v.end(),make_pair(b+1,0))-v.begin();
    return query(root[it],root[it2],1,n,b,n);
}
bool can(int m,int k[]){
    vector<int> K;
    K.push_back(0);
    for(int i = 0;i<m;i++){
        K.push_back(k[i]);
    }
    long long dp[m+1]; dp[0] =0;
    vector<pair<long long,long long> > v; // start pos, best-k
    v.push_back(make_pair(0LL,0LL));
    for (int x=1; x <= m; x++) {
        int lol = (--lower_bound(v.begin(), v.end(), make_pair((long long)x+1, 0LL)))->second;
        dp[x] = dp[lol] + w(K[lol], K[x]) - K[x];
        //cout<<K[lol]<<" "<<K[x]<<" "<<w(K[lol],K[x])<<endl; 
        for (int i = v.size()-1; i >= 0; i--) {
            int y = v[i].first, oldk = v[i].second;
            if (y > x && dp[x] + w(K[x], K[y]) - K[x] < dp[oldk] + w(K[oldk], K[y]) - K[y])
                v.pop_back();
            else {
                int lo = y+1, hi = m+1;
                while(lo < hi) {
                    int mid = (lo+hi)/2;
                    if (dp[x] + w(K[x], K[mid]) - K[mid] <= dp[oldk] + w(K[oldk], K[mid]) - K[mid])
                        hi = mid;
                    else
                        lo = mid+1;
                }
                if (hi != m+1) v.push_back(make_pair(hi, x));
                break;
            }
        }
        if (v.size() == 0)
            v.push_back(make_pair(0LL, x));
    }
    for(int i = 1;i<=m;i++){
        if(dp[i]<0)return 0;
    }
    return 1;
}

Compilation message

teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 1;i<=v.size();i++){
      |                   ~^~~~~~~~~~
teams.cpp: In function 'int w(int, int)':
teams.cpp:52:61: warning: conversion from '__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   52 |     int it = lower_bound(v.begin(),v.end(),make_pair(a+1,0))-v.begin();
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
teams.cpp:53:62: warning: conversion from '__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   53 |     int it2 = lower_bound(v.begin(),v.end(),make_pair(b+1,0))-v.begin();
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
teams.cpp: In function 'bool can(int, int*)':
teams.cpp:63:40: warning: declaration of 'v' shadows a global declaration [-Wshadow]
   63 |     vector<pair<long long,long long> > v; // start pos, best-k
      |                                        ^
teams.cpp:39:23: note: shadowed declaration is here
   39 | vector<pair<int,int>> v;
      |                       ^
teams.cpp:66:88: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   66 |         int lol = (--lower_bound(v.begin(), v.end(), make_pair((long long)x+1, 0LL)))->second;
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
teams.cpp:69:30: warning: conversion from 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   69 |         for (int i = v.size()-1; i >= 0; i--) {
      |                      ~~~~~~~~^~
teams.cpp:70:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   70 |             int y = v[i].first, oldk = v[i].second;
teams.cpp:70:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   70 |             int y = v[i].first, oldk = v[i].second;
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6556 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6608 KB Output is correct
5 Correct 1 ms 6744 KB Output is correct
6 Correct 7 ms 7004 KB Output is correct
7 Incorrect 2 ms 6492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 31940 KB Output is correct
2 Correct 42 ms 31940 KB Output is correct
3 Correct 38 ms 32168 KB Output is correct
4 Correct 222 ms 36808 KB Output is correct
5 Incorrect 28 ms 31712 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 399 ms 32704 KB Output is correct
2 Correct 403 ms 32676 KB Output is correct
3 Correct 184 ms 36048 KB Output is correct
4 Correct 195 ms 36748 KB Output is correct
5 Incorrect 424 ms 32452 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 178 ms 95504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -