Submission #628828

# Submission time Handle Problem Language Result Execution time Memory
628828 2022-08-13T17:55:45 Z cadmiumsky Catfish Farm (IOI22_fish) C++17
100 / 100
377 ms 25704 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define int ll

using ll = long long;
using pii = pair<int,int>;
const int nmax = 1e5 + 5, mmax = 3e5 + 5, inf = 1e15 + 5;
int n, m;
vector<pii> cat[nmax]; 

class DS {
  int l, r, flip;
  map<int,int> dp;
  void upd(int poz, int x) {
    if(dp.empty())
      return;
    auto it = dp.upper_bound(poz);
    if(prev(it) -> second >= x) {
      dp[poz] = x;
      return;
    }
    dp[poz] = x;
    while(it != dp.end()) {
      //cerr << poz << ' ' << x << " VS " << it -> first << ' ' << it -> second << '\n';
      if(it -> second <= x)
	dp.erase(it);
      else
	break;
      it = dp.upper_bound(poz);
    }
    return;
  }
  public:
    DS(int x, int val = 0) {
      flip = x;
      l = n + 1;
      r = 2 * n + 1;
      dp[l] = val; 
    }
    int get(int poz) {
      poz += l;
      if(flip) poz = r + l - poz;
      
      if(dp.empty()) return 0;
      auto it = dp.upper_bound(poz);
      if(it == dp.begin()) {
	print();
	assert(false); // oh golly gosh gee sper sa nu ma futa chestia asta cand poate debuggez; upd: da
      }
      
      return prev(it) -> second;
    } 
    void insert(int poz, int x) {
      poz += l;
      if(flip) poz = r + l - poz;
      
      upd(poz, x);
    }
    
    void push_front(int x) {
      l--;
      r--;
      
      if(!dp.empty() && dp.rbegin() -> first > r)
	dp.erase(dp.rbegin() -> first);
      if(dp.empty()) {
	dp[l] = x;
	return; 
      }
      dp[l] = x - 1;
      //cerr << flip << ": ";
      //print();
      upd(l, x);
    }
    void print() {
      cerr << "> " << l << ' ' << r << '\n';
      for(auto [p, x] : dp) {
	cerr << p << ' ' << x << '\n';
      }
      cerr << '\n';
    }
};

#undef int
long long max_weights(int N, int M, std::vector<int> x, std::vector<int> y, std::vector<int> cost) { // rezultatul este: Crescendo[N - 2].fin, Descrescendo[N - 1].deb (adica pune stalp inainte de ultima pozitie)
  #define int ll
  tie(n, m) = pii{N, M};
  for(int i = 0; i < m; i++) {
    cat[x[i]].emplace_back(y[i], cost[i]);
  }
  for(int i = 0; i < n; i++)
    sort(cat[i].begin(), cat[i].end());
  DS cresc(0), decresc(1, -inf);
  int mx = 0, lastcresc = 0, lastdecresc = 0;
  for(int i = 0; i < n; i++) {
    mx = max(lastcresc, mx);
    for(auto [h, w] : cat[i])
      cresc.insert(h, cresc.get(h) + w);
    for(int it = cat[i].size() - 1, h, w; it >= 0; it--) {
      tie(h, w) = cat[i][it];
      decresc.insert(h, decresc.get(h) + w);
    }
    
    //cerr << "<<<<<<<<<<<<<<<<<\n";
    //cerr << lastdecresc << ' ' << lastcresc << '\n';
    //cresc.print();
    //decresc.print();
    
    //cerr << ">>>>>>>>>>>>>>>>>\n";
    
    mx = max(decresc.get(0), mx);
    int temp  = max(0LL, decresc.get(0));
    decresc.push_front(max(lastcresc, lastdecresc));
    lastdecresc = max(0LL, temp);
    int temp2 = cresc.get(n - 1);
    cresc.push_front(max(lastcresc, temp));
    lastcresc = temp2;
  }
  return mx;
}
#undef int


//9 9
//0 0 1
//1 1 2
//2 2 3
//4 0 4
//4 2 5
//6 2 6
//7 1 7
//7 0 8
//8 0 9

//10 10
//0 0 2
//0 9 2
//2 0 2
//2 9 2
//4 0 2
//4 9 2
//6 0 2
//6 9 2
//8 0 2
//8 9 2

# Verdict Execution time Memory Grader output
1 Correct 115 ms 15808 KB Output is correct
2 Correct 166 ms 19096 KB Output is correct
3 Correct 13 ms 2644 KB Output is correct
4 Correct 14 ms 2644 KB Output is correct
5 Correct 377 ms 25704 KB Output is correct
6 Correct 190 ms 17420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 197 ms 19060 KB Output is correct
3 Correct 258 ms 23148 KB Output is correct
4 Correct 122 ms 15940 KB Output is correct
5 Correct 144 ms 19092 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 17 ms 2652 KB Output is correct
11 Correct 17 ms 2516 KB Output is correct
12 Correct 121 ms 16040 KB Output is correct
13 Correct 144 ms 19060 KB Output is correct
14 Correct 103 ms 10916 KB Output is correct
15 Correct 109 ms 11856 KB Output is correct
16 Correct 117 ms 13468 KB Output is correct
17 Correct 127 ms 14576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2644 KB Output is correct
2 Correct 13 ms 2644 KB Output is correct
3 Correct 39 ms 5596 KB Output is correct
4 Correct 29 ms 4564 KB Output is correct
5 Correct 77 ms 8128 KB Output is correct
6 Correct 54 ms 8052 KB Output is correct
7 Correct 55 ms 8020 KB Output is correct
8 Correct 58 ms 8132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 30 ms 4604 KB Output is correct
18 Correct 29 ms 5232 KB Output is correct
19 Correct 29 ms 5208 KB Output is correct
20 Correct 29 ms 5076 KB Output is correct
21 Correct 28 ms 5088 KB Output is correct
22 Correct 59 ms 7424 KB Output is correct
23 Correct 7 ms 3028 KB Output is correct
24 Correct 22 ms 4028 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 7 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 30 ms 4604 KB Output is correct
18 Correct 29 ms 5232 KB Output is correct
19 Correct 29 ms 5208 KB Output is correct
20 Correct 29 ms 5076 KB Output is correct
21 Correct 28 ms 5088 KB Output is correct
22 Correct 59 ms 7424 KB Output is correct
23 Correct 7 ms 3028 KB Output is correct
24 Correct 22 ms 4028 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 7 ms 3028 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 145 ms 13604 KB Output is correct
29 Correct 202 ms 16844 KB Output is correct
30 Correct 208 ms 16332 KB Output is correct
31 Correct 189 ms 16384 KB Output is correct
32 Correct 193 ms 18336 KB Output is correct
33 Correct 187 ms 16272 KB Output is correct
34 Correct 179 ms 16292 KB Output is correct
35 Correct 70 ms 8404 KB Output is correct
36 Correct 194 ms 18252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2644 KB Output is correct
2 Correct 13 ms 2644 KB Output is correct
3 Correct 39 ms 5596 KB Output is correct
4 Correct 29 ms 4564 KB Output is correct
5 Correct 77 ms 8128 KB Output is correct
6 Correct 54 ms 8052 KB Output is correct
7 Correct 55 ms 8020 KB Output is correct
8 Correct 58 ms 8132 KB Output is correct
9 Correct 57 ms 8056 KB Output is correct
10 Correct 58 ms 7668 KB Output is correct
11 Correct 111 ms 12568 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 17 ms 2648 KB Output is correct
19 Correct 16 ms 2644 KB Output is correct
20 Correct 13 ms 2628 KB Output is correct
21 Correct 12 ms 2648 KB Output is correct
22 Correct 69 ms 7648 KB Output is correct
23 Correct 121 ms 12544 KB Output is correct
24 Correct 121 ms 12572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 15808 KB Output is correct
2 Correct 166 ms 19096 KB Output is correct
3 Correct 13 ms 2644 KB Output is correct
4 Correct 14 ms 2644 KB Output is correct
5 Correct 377 ms 25704 KB Output is correct
6 Correct 190 ms 17420 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 197 ms 19060 KB Output is correct
9 Correct 258 ms 23148 KB Output is correct
10 Correct 122 ms 15940 KB Output is correct
11 Correct 144 ms 19092 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 17 ms 2652 KB Output is correct
17 Correct 17 ms 2516 KB Output is correct
18 Correct 121 ms 16040 KB Output is correct
19 Correct 144 ms 19060 KB Output is correct
20 Correct 103 ms 10916 KB Output is correct
21 Correct 109 ms 11856 KB Output is correct
22 Correct 117 ms 13468 KB Output is correct
23 Correct 127 ms 14576 KB Output is correct
24 Correct 20 ms 2644 KB Output is correct
25 Correct 13 ms 2644 KB Output is correct
26 Correct 39 ms 5596 KB Output is correct
27 Correct 29 ms 4564 KB Output is correct
28 Correct 77 ms 8128 KB Output is correct
29 Correct 54 ms 8052 KB Output is correct
30 Correct 55 ms 8020 KB Output is correct
31 Correct 58 ms 8132 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 3 ms 2644 KB Output is correct
48 Correct 30 ms 4604 KB Output is correct
49 Correct 29 ms 5232 KB Output is correct
50 Correct 29 ms 5208 KB Output is correct
51 Correct 29 ms 5076 KB Output is correct
52 Correct 28 ms 5088 KB Output is correct
53 Correct 59 ms 7424 KB Output is correct
54 Correct 7 ms 3028 KB Output is correct
55 Correct 22 ms 4028 KB Output is correct
56 Correct 3 ms 2644 KB Output is correct
57 Correct 7 ms 3028 KB Output is correct
58 Correct 3 ms 2772 KB Output is correct
59 Correct 145 ms 13604 KB Output is correct
60 Correct 202 ms 16844 KB Output is correct
61 Correct 208 ms 16332 KB Output is correct
62 Correct 189 ms 16384 KB Output is correct
63 Correct 193 ms 18336 KB Output is correct
64 Correct 187 ms 16272 KB Output is correct
65 Correct 179 ms 16292 KB Output is correct
66 Correct 70 ms 8404 KB Output is correct
67 Correct 194 ms 18252 KB Output is correct
68 Correct 57 ms 8056 KB Output is correct
69 Correct 58 ms 7668 KB Output is correct
70 Correct 111 ms 12568 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 1 ms 2644 KB Output is correct
73 Correct 1 ms 2644 KB Output is correct
74 Correct 1 ms 2644 KB Output is correct
75 Correct 2 ms 2644 KB Output is correct
76 Correct 2 ms 2644 KB Output is correct
77 Correct 17 ms 2648 KB Output is correct
78 Correct 16 ms 2644 KB Output is correct
79 Correct 13 ms 2628 KB Output is correct
80 Correct 12 ms 2648 KB Output is correct
81 Correct 69 ms 7648 KB Output is correct
82 Correct 121 ms 12544 KB Output is correct
83 Correct 121 ms 12572 KB Output is correct
84 Correct 255 ms 17032 KB Output is correct
85 Correct 251 ms 17100 KB Output is correct
86 Correct 203 ms 17356 KB Output is correct
87 Correct 202 ms 17508 KB Output is correct
88 Correct 1 ms 2644 KB Output is correct
89 Correct 204 ms 17520 KB Output is correct
90 Correct 197 ms 17552 KB Output is correct
91 Correct 184 ms 17316 KB Output is correct