답안 #719433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
719433 2023-04-05T22:31:49 Z somethingnew 송신탑 (IOI22_towers) C++17
56 / 100
3200 ms 208548 KB
//  ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
//  ➡ @roadfromroi ⬅
//  ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "queue"
#include "towers.h"
#define all(x) x.begin(), x.end()
using namespace std;

vector<int> h;
int dd;
struct node {
    int lval;
    int rval;
    int cnt;
    int lstenka;
    int rstenka;
    node() {}
    node(int x) {
        lval = rval = x;
        cnt = 1;
        lstenka = 0;
        rstenka = 0;
    }
    void swapchik() {
        swap(lval, rval);
        swap(lstenka, rstenka);
    }
};

void merge(node &a, node b) {
    bool swp = 0;
    if (a.rval > b.lval) {
        swp = 1;
        a.swapchik();
        b.swapchik();
        swap(a, b);
    }
    if (max(a.rstenka, b.lstenka) - dd >= max(a.rval, b.lval)) {
        a.cnt = a.cnt + b.cnt;
        a.rstenka = b.rstenka;
        a.rval = b.rval;
        if (swp)
            a.swapchik();
        return;
    } else {
        a.cnt = a.cnt + b.cnt - 1;
        if (b.cnt != 1) {
            a.rstenka = b.rstenka;
            a.rval = b.rval;
        } else {
          //  cout << c.rstenka << ' ';
            a.rstenka = max(a.rstenka, max(b.rstenka, max(b.lstenka, b.rval)));
          //  cout << c.rstenka << '\n';
        }
        if (swp)
            a.swapchik();
        return;
    }
}
struct kornihunka{
    vector<int> elems;
    node nd;
    void push(int x) {
        elems.push_back(x);
    }
    node get(int l, int r) {
        r = min(r, (int)elems.size() - 1);
        node nres(elems[l]);
        for (int i = l + 1; i <= r; ++i) {
            merge(nres, node(elems[i]));
        }
        return nres;
    }
    void calc() {
        nd = node(elems[0]);
        for (int i = 1; i < elems.size(); ++i) {
            merge(nd, elems[i]);
        }
    }
    node getnode() {
        return nd;
    }
};
int K = 337;
vector<vector<kornihunka>> vecnode;
int calcedd = 0;
void init(int n, vector<int> hh) {
    h = hh;
    vecnode.assign((n + K - 1) / K, vector<kornihunka>(K));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < K; ++j) {
            vecnode[i/K][j].push(h[i]);
        }
    }
}
int max_towers(int L, int R, int D) {
    node res(2e9);
    if (calcedd != D) {
        if (calcedd != 0)
            exit(1);
        calcedd = D;
        dd = D;
        for (int i = 0; i < vecnode.size(); ++i) {
            for (int j = 0; j < K; ++j) {
                vecnode[i][j].calc();
            }
        }
    }
    if (L / K == R / K) {
   //     cout << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
        merge(res, vecnode[L/K][0].get(L % K, R % K));
        return res.cnt;
    }
    if (L % K != 0) {
      //  cout << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
        merge(res, vecnode[L/K][0].get(L % K, K - 1));
        L = L / K * K + K;
    }
    while (L + K <= R + 1) {
        //cout << "TT " << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
        node res2 = vecnode[L/K][0].getnode();
        //cout << "TT2 " << res2.lval << ' ' << res2.lstenka << ' ' << res2.cnt << '\n';
        merge(res, vecnode[L/K][0].getnode());
        //cout << "TT3 " << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';

        L += K;
    }
    if (L <= R) {
       // cout << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
        merge(res, vecnode[L/K][0].get(L % K, R % K));
    }
   // cout << res.rval << ' ' << res.rstenka << ' ' << res.cnt << '\n';
    return res.cnt;
}
/*
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    init(n, a);
    for (int i = 0; i < m; ++i) {
        int q1, q2, q3;
        cin >> q1 >> q2 >> q3;
        cout << max_towers(q1,q2,q3) << '\n';
    }
}*/
/*
7 1
10 20 60 40 50 30 70
0 6 17
 */

Compilation message

towers.cpp: In member function 'void kornihunka::calc()':
towers.cpp:88:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for (int i = 1; i < elems.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:115:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<kornihunka> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for (int i = 0; i < vecnode.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~~~~
towers.cpp:133:14: warning: variable 'res2' set but not used [-Wunused-but-set-variable]
  133 |         node res2 = vecnode[L/K][0].getnode();
      |              ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 589 ms 124676 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1104 KB Output is correct
2 Correct 24 ms 4556 KB Output is correct
3 Correct 21 ms 4508 KB Output is correct
4 Correct 22 ms 4432 KB Output is correct
5 Correct 21 ms 4432 KB Output is correct
6 Correct 23 ms 4544 KB Output is correct
7 Correct 19 ms 4432 KB Output is correct
8 Correct 19 ms 4432 KB Output is correct
9 Correct 26 ms 4480 KB Output is correct
10 Correct 18 ms 4544 KB Output is correct
11 Correct 25 ms 4548 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 25 ms 4540 KB Output is correct
14 Correct 26 ms 4476 KB Output is correct
15 Correct 23 ms 4432 KB Output is correct
16 Correct 23 ms 4444 KB Output is correct
17 Correct 22 ms 4552 KB Output is correct
18 Correct 29 ms 4564 KB Output is correct
19 Correct 19 ms 4548 KB Output is correct
20 Correct 24 ms 4528 KB Output is correct
21 Correct 22 ms 4532 KB Output is correct
22 Correct 22 ms 4432 KB Output is correct
23 Correct 26 ms 4488 KB Output is correct
24 Correct 19 ms 4432 KB Output is correct
25 Correct 9 ms 2004 KB Output is correct
26 Correct 20 ms 4492 KB Output is correct
27 Correct 22 ms 4444 KB Output is correct
28 Correct 22 ms 4444 KB Output is correct
29 Correct 23 ms 4548 KB Output is correct
30 Correct 21 ms 4548 KB Output is correct
31 Correct 21 ms 4552 KB Output is correct
32 Correct 19 ms 4548 KB Output is correct
33 Correct 28 ms 4528 KB Output is correct
34 Correct 18 ms 4432 KB Output is correct
35 Correct 26 ms 4552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1104 KB Output is correct
2 Correct 24 ms 4556 KB Output is correct
3 Correct 21 ms 4508 KB Output is correct
4 Correct 22 ms 4432 KB Output is correct
5 Correct 21 ms 4432 KB Output is correct
6 Correct 23 ms 4544 KB Output is correct
7 Correct 19 ms 4432 KB Output is correct
8 Correct 19 ms 4432 KB Output is correct
9 Correct 26 ms 4480 KB Output is correct
10 Correct 18 ms 4544 KB Output is correct
11 Correct 25 ms 4548 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 25 ms 4540 KB Output is correct
14 Correct 26 ms 4476 KB Output is correct
15 Correct 23 ms 4432 KB Output is correct
16 Correct 23 ms 4444 KB Output is correct
17 Correct 22 ms 4552 KB Output is correct
18 Correct 29 ms 4564 KB Output is correct
19 Correct 19 ms 4548 KB Output is correct
20 Correct 24 ms 4528 KB Output is correct
21 Correct 22 ms 4532 KB Output is correct
22 Correct 22 ms 4432 KB Output is correct
23 Correct 26 ms 4488 KB Output is correct
24 Correct 19 ms 4432 KB Output is correct
25 Correct 9 ms 2004 KB Output is correct
26 Correct 20 ms 4492 KB Output is correct
27 Correct 22 ms 4444 KB Output is correct
28 Correct 22 ms 4444 KB Output is correct
29 Correct 23 ms 4548 KB Output is correct
30 Correct 21 ms 4548 KB Output is correct
31 Correct 21 ms 4552 KB Output is correct
32 Correct 19 ms 4548 KB Output is correct
33 Correct 28 ms 4528 KB Output is correct
34 Correct 18 ms 4432 KB Output is correct
35 Correct 26 ms 4552 KB Output is correct
36 Correct 738 ms 135968 KB Output is correct
37 Correct 990 ms 208360 KB Output is correct
38 Correct 1098 ms 208548 KB Output is correct
39 Correct 975 ms 208356 KB Output is correct
40 Correct 1113 ms 208340 KB Output is correct
41 Correct 1091 ms 208380 KB Output is correct
42 Correct 1084 ms 208364 KB Output is correct
43 Correct 922 ms 208284 KB Output is correct
44 Correct 1321 ms 208312 KB Output is correct
45 Correct 924 ms 208352 KB Output is correct
46 Correct 1299 ms 208376 KB Output is correct
47 Correct 1143 ms 208448 KB Output is correct
48 Correct 1077 ms 208252 KB Output is correct
49 Correct 1108 ms 208360 KB Output is correct
50 Correct 1296 ms 208348 KB Output is correct
51 Correct 932 ms 208348 KB Output is correct
52 Correct 1142 ms 208284 KB Output is correct
53 Correct 1083 ms 208328 KB Output is correct
54 Correct 1104 ms 208368 KB Output is correct
55 Correct 1332 ms 208348 KB Output is correct
56 Correct 956 ms 208352 KB Output is correct
57 Correct 1086 ms 201292 KB Output is correct
58 Correct 1240 ms 208296 KB Output is correct
59 Correct 1188 ms 208340 KB Output is correct
60 Correct 1132 ms 208252 KB Output is correct
61 Correct 1152 ms 208260 KB Output is correct
62 Correct 1205 ms 208272 KB Output is correct
63 Correct 1125 ms 208296 KB Output is correct
64 Correct 962 ms 208320 KB Output is correct
65 Correct 1365 ms 208296 KB Output is correct
66 Correct 946 ms 208324 KB Output is correct
67 Correct 1356 ms 208260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2602 ms 206924 KB Output is correct
2 Correct 3004 ms 208300 KB Output is correct
3 Correct 2644 ms 208420 KB Output is correct
4 Correct 2772 ms 208328 KB Output is correct
5 Correct 2704 ms 208436 KB Output is correct
6 Correct 2741 ms 208260 KB Output is correct
7 Correct 2746 ms 208456 KB Output is correct
8 Correct 2219 ms 208480 KB Output is correct
9 Correct 3046 ms 208264 KB Output is correct
10 Correct 2282 ms 208288 KB Output is correct
11 Correct 3015 ms 208304 KB Output is correct
12 Correct 2210 ms 208316 KB Output is correct
13 Correct 3063 ms 208300 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 26 ms 4432 KB Output is correct
16 Correct 27 ms 4432 KB Output is correct
17 Correct 1137 ms 208308 KB Output is correct
18 Correct 1147 ms 208528 KB Output is correct
19 Correct 1068 ms 208328 KB Output is correct
20 Correct 1280 ms 208340 KB Output is correct
21 Correct 922 ms 208324 KB Output is correct
22 Correct 1143 ms 208348 KB Output is correct
23 Correct 1087 ms 208472 KB Output is correct
24 Correct 1083 ms 208284 KB Output is correct
25 Correct 1273 ms 208392 KB Output is correct
26 Correct 925 ms 208396 KB Output is correct
27 Correct 23 ms 4432 KB Output is correct
28 Correct 22 ms 4552 KB Output is correct
29 Correct 23 ms 4544 KB Output is correct
30 Correct 26 ms 4544 KB Output is correct
31 Correct 19 ms 4432 KB Output is correct
32 Correct 23 ms 4480 KB Output is correct
33 Correct 22 ms 4424 KB Output is correct
34 Correct 22 ms 4544 KB Output is correct
35 Correct 27 ms 4544 KB Output is correct
36 Correct 18 ms 4548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 273 ms 50236 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1104 KB Output is correct
2 Correct 24 ms 4556 KB Output is correct
3 Correct 21 ms 4508 KB Output is correct
4 Correct 22 ms 4432 KB Output is correct
5 Correct 21 ms 4432 KB Output is correct
6 Correct 23 ms 4544 KB Output is correct
7 Correct 19 ms 4432 KB Output is correct
8 Correct 19 ms 4432 KB Output is correct
9 Correct 26 ms 4480 KB Output is correct
10 Correct 18 ms 4544 KB Output is correct
11 Correct 25 ms 4548 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 25 ms 4540 KB Output is correct
14 Correct 26 ms 4476 KB Output is correct
15 Correct 23 ms 4432 KB Output is correct
16 Correct 23 ms 4444 KB Output is correct
17 Correct 22 ms 4552 KB Output is correct
18 Correct 29 ms 4564 KB Output is correct
19 Correct 19 ms 4548 KB Output is correct
20 Correct 24 ms 4528 KB Output is correct
21 Correct 22 ms 4532 KB Output is correct
22 Correct 22 ms 4432 KB Output is correct
23 Correct 26 ms 4488 KB Output is correct
24 Correct 19 ms 4432 KB Output is correct
25 Correct 9 ms 2004 KB Output is correct
26 Correct 20 ms 4492 KB Output is correct
27 Correct 22 ms 4444 KB Output is correct
28 Correct 22 ms 4444 KB Output is correct
29 Correct 23 ms 4548 KB Output is correct
30 Correct 21 ms 4548 KB Output is correct
31 Correct 21 ms 4552 KB Output is correct
32 Correct 19 ms 4548 KB Output is correct
33 Correct 28 ms 4528 KB Output is correct
34 Correct 18 ms 4432 KB Output is correct
35 Correct 26 ms 4552 KB Output is correct
36 Correct 738 ms 135968 KB Output is correct
37 Correct 990 ms 208360 KB Output is correct
38 Correct 1098 ms 208548 KB Output is correct
39 Correct 975 ms 208356 KB Output is correct
40 Correct 1113 ms 208340 KB Output is correct
41 Correct 1091 ms 208380 KB Output is correct
42 Correct 1084 ms 208364 KB Output is correct
43 Correct 922 ms 208284 KB Output is correct
44 Correct 1321 ms 208312 KB Output is correct
45 Correct 924 ms 208352 KB Output is correct
46 Correct 1299 ms 208376 KB Output is correct
47 Correct 1143 ms 208448 KB Output is correct
48 Correct 1077 ms 208252 KB Output is correct
49 Correct 1108 ms 208360 KB Output is correct
50 Correct 1296 ms 208348 KB Output is correct
51 Correct 932 ms 208348 KB Output is correct
52 Correct 1142 ms 208284 KB Output is correct
53 Correct 1083 ms 208328 KB Output is correct
54 Correct 1104 ms 208368 KB Output is correct
55 Correct 1332 ms 208348 KB Output is correct
56 Correct 956 ms 208352 KB Output is correct
57 Correct 1086 ms 201292 KB Output is correct
58 Correct 1240 ms 208296 KB Output is correct
59 Correct 1188 ms 208340 KB Output is correct
60 Correct 1132 ms 208252 KB Output is correct
61 Correct 1152 ms 208260 KB Output is correct
62 Correct 1205 ms 208272 KB Output is correct
63 Correct 1125 ms 208296 KB Output is correct
64 Correct 962 ms 208320 KB Output is correct
65 Correct 1365 ms 208296 KB Output is correct
66 Correct 946 ms 208324 KB Output is correct
67 Correct 1356 ms 208260 KB Output is correct
68 Correct 2602 ms 206924 KB Output is correct
69 Correct 3004 ms 208300 KB Output is correct
70 Correct 2644 ms 208420 KB Output is correct
71 Correct 2772 ms 208328 KB Output is correct
72 Correct 2704 ms 208436 KB Output is correct
73 Correct 2741 ms 208260 KB Output is correct
74 Correct 2746 ms 208456 KB Output is correct
75 Correct 2219 ms 208480 KB Output is correct
76 Correct 3046 ms 208264 KB Output is correct
77 Correct 2282 ms 208288 KB Output is correct
78 Correct 3015 ms 208304 KB Output is correct
79 Correct 2210 ms 208316 KB Output is correct
80 Correct 3063 ms 208300 KB Output is correct
81 Correct 1 ms 208 KB Output is correct
82 Correct 26 ms 4432 KB Output is correct
83 Correct 27 ms 4432 KB Output is correct
84 Correct 1137 ms 208308 KB Output is correct
85 Correct 1147 ms 208528 KB Output is correct
86 Correct 1068 ms 208328 KB Output is correct
87 Correct 1280 ms 208340 KB Output is correct
88 Correct 922 ms 208324 KB Output is correct
89 Correct 1143 ms 208348 KB Output is correct
90 Correct 1087 ms 208472 KB Output is correct
91 Correct 1083 ms 208284 KB Output is correct
92 Correct 1273 ms 208392 KB Output is correct
93 Correct 925 ms 208396 KB Output is correct
94 Correct 23 ms 4432 KB Output is correct
95 Correct 22 ms 4552 KB Output is correct
96 Correct 23 ms 4544 KB Output is correct
97 Correct 26 ms 4544 KB Output is correct
98 Correct 19 ms 4432 KB Output is correct
99 Correct 23 ms 4480 KB Output is correct
100 Correct 22 ms 4424 KB Output is correct
101 Correct 22 ms 4544 KB Output is correct
102 Correct 27 ms 4544 KB Output is correct
103 Correct 18 ms 4548 KB Output is correct
104 Correct 2340 ms 185064 KB Output is correct
105 Correct 2851 ms 208500 KB Output is correct
106 Correct 2602 ms 208284 KB Output is correct
107 Correct 2624 ms 208368 KB Output is correct
108 Correct 2517 ms 208440 KB Output is correct
109 Correct 2854 ms 208456 KB Output is correct
110 Correct 2605 ms 208316 KB Output is correct
111 Correct 2261 ms 208316 KB Output is correct
112 Correct 3028 ms 208328 KB Output is correct
113 Correct 2242 ms 208372 KB Output is correct
114 Correct 3200 ms 208328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 589 ms 124676 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -