Submission #428911

# Submission time Handle Problem Language Result Execution time Memory
428911 2021-06-15T15:24:49 Z Pety Global Warming (CEOI18_glo) C++14
100 / 100
1582 ms 40792 KB
#include <bits/stdc++.h>
     
using namespace std;
     
     
int n, x, pref[200002], suf[200002], v[200002];
vector<int>aux;
int aint[4 * 3 * 200000 + 2];
unordered_map<int, int>mp;
void update (int nod, int st, int dr, int poz, int val) {
  if (st == dr) {
   aint[nod] = val;
   return;
  }
  int mij = (st + dr) / 2;
  if (poz <= mij)
    update(2 * nod, st, mij, poz, val);
  else
    update(2 * nod + 1, mij + 1, dr, poz, val);
  aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]);
}     
int ans = 0;     
void query (int nod, int st, int dr, int a, int b) {
  if (a > b)
    return;
  if (a <= st && dr <= b) {
    ans = max(ans, aint[nod]);
    return;
  }
  int mij = (st + dr) / 2;
  if (a <= mij)
    query(2 * nod, st, mij, a, b);
  if (b > mij)
    query(2 * nod + 1, mij + 1, dr, a, b);
}     
int nr = 0;     
void reset () {
  for (int i = 1; i <= 4*nr; i++)
    aint[i] = 0;
}
     
int main() {
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {      cin >> v[i];
    aux.push_back(v[i] + x);
    aux.push_back(v[i] - x);
    aux.push_back(v[i]);
  }
  sort(aux.begin(), aux.end());
  for (int i = 0; i < aux.size(); i++)
    if (i == 0 || aux[i] != aux[i - 1]) {
      nr++;
      mp[aux[i]] = nr;
    }
  int sol = 0;
  for (int i = 1; i <= n; i++) {
    ans = 0;
    assert(mp[v[i]]);
    query(1, 1, nr, 1, mp[v[i]] - 1);
    pref[i] = ans + 1;
    update(1, 1, nr, mp[v[i]], pref[i]);
    sol = max(ans, pref[i]);
    //cout << pref[i] << "\n";
  }
  reset();
  for (int i = n; i >= 1; i--) {
    ans = 0;
    query(1, 1, nr, mp[v[i]] + 1, nr);
    suf[i] = ans + 1;
    update(1, 1, nr, mp[v[i]], suf[i]);
  }
  reset();
  for (int i = 1; i <= n; i++) {
    ans = 0;
    query(1, 1, nr, 1, mp[v[i] + x] - 1);
    sol = max(suf[i] + ans, sol);
    update(1, 1, nr, mp[v[i]], pref[i]);
  }
  reset();
  for (int i = n; i >= 1; i--) {
    ans = 0;
    query(1, 1, nr, mp[v[i] - x] + 1, nr);
    sol = max(sol, ans + pref[i]);
    update(1, 1, nr, mp[v[i]], suf[i]);
  }
  cout << sol << "\n";
  return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for (int i = 0; i < aux.size(); i++)
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 3 ms 460 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 460 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 3 ms 284 KB Output is correct
26 Correct 3 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1020 ms 19464 KB Output is correct
2 Correct 1024 ms 19480 KB Output is correct
3 Correct 899 ms 19488 KB Output is correct
4 Correct 904 ms 19472 KB Output is correct
5 Correct 455 ms 12360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 9884 KB Output is correct
2 Correct 276 ms 9884 KB Output is correct
3 Correct 261 ms 9868 KB Output is correct
4 Correct 101 ms 5668 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 84 ms 4476 KB Output is correct
7 Correct 178 ms 8200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 698 ms 19688 KB Output is correct
2 Correct 673 ms 19572 KB Output is correct
3 Correct 1582 ms 38792 KB Output is correct
4 Correct 644 ms 21928 KB Output is correct
5 Correct 221 ms 19500 KB Output is correct
6 Correct 453 ms 36996 KB Output is correct
7 Correct 452 ms 37032 KB Output is correct
8 Correct 520 ms 19536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 3 ms 460 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 460 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 3 ms 284 KB Output is correct
26 Correct 3 ms 420 KB Output is correct
27 Correct 1020 ms 19464 KB Output is correct
28 Correct 1024 ms 19480 KB Output is correct
29 Correct 899 ms 19488 KB Output is correct
30 Correct 904 ms 19472 KB Output is correct
31 Correct 455 ms 12360 KB Output is correct
32 Correct 234 ms 9884 KB Output is correct
33 Correct 276 ms 9884 KB Output is correct
34 Correct 261 ms 9868 KB Output is correct
35 Correct 101 ms 5668 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 84 ms 4476 KB Output is correct
38 Correct 178 ms 8200 KB Output is correct
39 Correct 698 ms 19688 KB Output is correct
40 Correct 673 ms 19572 KB Output is correct
41 Correct 1582 ms 38792 KB Output is correct
42 Correct 644 ms 21928 KB Output is correct
43 Correct 221 ms 19500 KB Output is correct
44 Correct 453 ms 36996 KB Output is correct
45 Correct 452 ms 37032 KB Output is correct
46 Correct 520 ms 19536 KB Output is correct
47 Correct 581 ms 20444 KB Output is correct
48 Correct 656 ms 20460 KB Output is correct
49 Correct 1540 ms 40792 KB Output is correct
50 Correct 592 ms 23016 KB Output is correct
51 Correct 279 ms 16736 KB Output is correct
52 Correct 376 ms 18852 KB Output is correct
53 Correct 428 ms 39920 KB Output is correct
54 Correct 506 ms 40588 KB Output is correct
55 Correct 977 ms 34508 KB Output is correct