Submission #1015441

# Submission time Handle Problem Language Result Execution time Memory
1015441 2024-07-06T10:48:06 Z cadmiumsky Teams (IOI15_teams) C++17
100 / 100
1462 ms 105664 KB
#include "teams.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

#define lsb(x) (x & -x)
struct AIB {
   int faking = 1;
   vector<int> nrm;
   vector<int> tree;
   AIB(): faking(1) { nrm.clear(); tree.clear(); }
   void upd(int p, int x) {
      if(faking) { nrm.emplace_back(p); return; } 
      p = distance(begin(nrm), upper_bound(all(nrm), p));
      while(p > 0) tree[p] += x, p -= lsb(p);
      return;
   }
   int query(int p) {
      int sum  = 0;
      assert(!faking);
      p = distance(begin(nrm), lower_bound(all(nrm), p)) + 1;
      while(p < sz(tree)) sum += tree[p], p += lsb(p);
      return sum;
   }
   void donefaking() {
      faking = 0;
      sort(all(nrm));
      nrm.erase(unique(all(nrm)), end(nrm));
      tree.resize(sz(nrm) + 2, 0);
   }
};

struct AIB2D {
   vector<AIB> tree;
   void init(int n) {
      tree.assign(n + 2, AIB());
   }
   int query(int l, int r) {
      int sum = 0;
      
      
      while(l > 0) {
         sum += tree[l].query(r);
         l -= lsb(l);
      }
      
      return sum;
   }
   void upd(int l, int r, int x) {
      while(l < sz(tree)) 
         tree[l].upd(r, x),
         l += lsb(l);
      return;
   }
   void donefaking() { for(auto &x : tree) x.donefaking(); }
};

AIB2D sums;

vector<pii> pula;

int Query(int x) {
   int a = sums.query(x, x);
   return a;
}
int Query(int x, int not_y) {
   return sums.query(x, x) - sums.query(x, not_y);
}
void init(int n, int A[], int B[]) {
   sums.init(n + 1);
   for(int i = 0; i < n; i++) 
      pula.emplace_back(A[i], B[i]),
      sums.upd(A[i], B[i], 1);
   sums.donefaking();
   for(int i = 0; i < n; i++) 
      sums.upd(A[i], B[i], 1);
   return;
   
}

int can(int M, int K[]) {
   int sofar = 0;
   sort(K, K + M);
   
   vector<int> dp(M, 0);
   
   for(int i = 0; i < M; i++) {
      for(int j = i - 1, a = 0; a <= 4 && j >= 0; a++, j--) // trebuie sa incerc
         dp[i] = min(dp[i], dp[j] + Query(K[j], K[i]) - K[j]);
      if(dp[i] + Query(K[i]) - K[i] < 0) return 0;
   }
   return 1;
}

Compilation message

teams.cpp: In member function 'void AIB::upd(int, int)':
teams.cpp:23:19: warning: conversion from 'std::__iterator_traits<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, void>::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   23 |       p = distance(begin(nrm), upper_bound(all(nrm), p));
      |           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp: In member function 'int AIB::query(int)':
teams.cpp:30:58: warning: conversion from 'std::__iterator_traits<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, void>::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   30 |       p = distance(begin(nrm), lower_bound(all(nrm), p)) + 1;
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:91:8: warning: unused variable 'sofar' [-Wunused-variable]
   91 |    int sofar = 0;
      |        ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 19300 KB Output is correct
2 Correct 162 ms 19140 KB Output is correct
3 Correct 168 ms 19144 KB Output is correct
4 Correct 155 ms 20120 KB Output is correct
5 Correct 77 ms 16328 KB Output is correct
6 Correct 75 ms 16428 KB Output is correct
7 Correct 73 ms 16236 KB Output is correct
8 Correct 71 ms 16324 KB Output is correct
9 Correct 44 ms 18384 KB Output is correct
10 Correct 44 ms 18112 KB Output is correct
11 Correct 41 ms 18120 KB Output is correct
12 Correct 58 ms 18056 KB Output is correct
13 Correct 75 ms 17160 KB Output is correct
14 Correct 151 ms 20424 KB Output is correct
15 Correct 122 ms 18624 KB Output is correct
16 Correct 120 ms 18632 KB Output is correct
17 Correct 44 ms 15560 KB Output is correct
18 Correct 47 ms 15816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 19656 KB Output is correct
2 Correct 154 ms 19544 KB Output is correct
3 Correct 208 ms 22472 KB Output is correct
4 Correct 160 ms 19908 KB Output is correct
5 Correct 122 ms 16584 KB Output is correct
6 Correct 114 ms 16664 KB Output is correct
7 Correct 81 ms 16584 KB Output is correct
8 Correct 118 ms 16584 KB Output is correct
9 Correct 44 ms 18400 KB Output is correct
10 Correct 46 ms 18372 KB Output is correct
11 Correct 57 ms 18632 KB Output is correct
12 Correct 105 ms 18372 KB Output is correct
13 Correct 228 ms 17732 KB Output is correct
14 Correct 224 ms 21444 KB Output is correct
15 Correct 145 ms 18884 KB Output is correct
16 Correct 143 ms 19008 KB Output is correct
17 Correct 61 ms 16024 KB Output is correct
18 Correct 60 ms 16068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1214 ms 99108 KB Output is correct
2 Correct 1142 ms 99240 KB Output is correct
3 Correct 1380 ms 105664 KB Output is correct
4 Correct 1194 ms 100012 KB Output is correct
5 Correct 610 ms 81336 KB Output is correct
6 Correct 550 ms 81848 KB Output is correct
7 Correct 518 ms 81348 KB Output is correct
8 Correct 578 ms 81592 KB Output is correct
9 Correct 251 ms 90576 KB Output is correct
10 Correct 273 ms 90348 KB Output is correct
11 Correct 336 ms 90044 KB Output is correct
12 Correct 468 ms 90552 KB Output is correct
13 Correct 927 ms 87020 KB Output is correct
14 Correct 1462 ms 104380 KB Output is correct
15 Correct 826 ms 92468 KB Output is correct
16 Correct 765 ms 92836 KB Output is correct
17 Correct 271 ms 78936 KB Output is correct
18 Correct 273 ms 79548 KB Output is correct