Submission #747493

# Submission time Handle Problem Language Result Execution time Memory
747493 2023-05-24T08:27:36 Z vjudge1 Kralj (COCI16_kralj) C++17
56 / 140
539 ms 98116 KB
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
 
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define endl '\n'
#define int long long
#define mod 998244353;
using namespace std;
int a[2000001],p[2000001],v[2000001];
int freq[2000001],pre[2000001],suf[2000001];
vector<int>store[2000001];
int vs[2000001],mn[2000001];
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, ans = 0; cin >> n;
    
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> p[i];
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
        store[a[i]].push_back(v[i]);
    }
    for(int i = 1; i <= n; i++) freq[a[i]]++;
    for(int i = 1; i <= n; i++) pre[i] += pre[i - 1] + freq[i];
    for(int i = n; i >= 1; i--) suf[i] += suf[i + 1] + freq[i];
    
    
    for(int i = n; i >= 1; i--){
        int f = suf[i];
        suf[i] = n - i + 1 - f;
    }
    
    mn[n + 1] = 0;
    for(int i = n; i >= 1; i--) mn[i] = max(mn[i + 1], suf[i]);
    
    int starting_point = 0;
    
    for(int i = 1; i < n; i++){
        if(pre[i] <= i and pre[i] - i <= mn[i + 1]){
            starting_point = i;
        }
    }
    multiset<int>idk;
    
    for(int i = starting_point; i <= n; i++){
        int j = 0;
        while(j < store[i].size()){
            idk.insert(store[i][j]);
            j++;
        }
        auto f = idk.lower_bound(p[i]);
        if(f != idk.end()){
            ans++;
            idk.erase(f);
        }else{
            idk.erase(*idk.begin());
        }
    }
    
    for(int i = 1; i <= starting_point; i++){
        if(i == starting_point){
            if(vs[i]) continue;
        }else{
            int j = 0;
            while(j < store[i].size()){
                idk.insert(store[i][j]);
                j++;
            }
        }
        auto f = idk.lower_bound(p[i]);
        if(f != idk.end()){
            ans++;
            idk.erase(f);
        }else{
            idk.erase(*idk.begin());
        }
    }
    cout << ans;
    
    return 0;
}
/*
 
 
 5 6 30 4
 1 0 5
 0 2 2
 2 3 4
 3 4 1
 2 4 3
 0 3 1
 1 1 1 1 1
 */

Compilation message

kralj.cpp: In function 'int main()':
kralj.cpp:129:17: 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]
  129 |         while(j < store[i].size()){
      |               ~~^~~~~~~~~~~~~~~~~
kralj.cpp:147:21: 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]
  147 |             while(j < store[i].size()){
      |                   ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 539 ms 88072 KB Output is correct
2 Correct 345 ms 87072 KB Output is correct
3 Correct 450 ms 96860 KB Output is correct
4 Correct 451 ms 98116 KB Output is correct
5 Incorrect 313 ms 78412 KB Output isn't correct
6 Incorrect 296 ms 78612 KB Output isn't correct
7 Incorrect 341 ms 81224 KB Output isn't correct
8 Incorrect 293 ms 78088 KB Output isn't correct
9 Incorrect 356 ms 83100 KB Output isn't correct
10 Incorrect 340 ms 81532 KB Output isn't correct