답안 #202673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202673 2020-02-17T17:16:55 Z ismagilov Fire (JOI20_ho_t5) C++14
100 / 100
711 ms 76960 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Azat Ismagilov
 */

                                         /*..         ....
                                    ..',,'..............''...'''.','..
                                  .';'..                          ..',,'.
                                 .'..                                 .';,.
                                .'.              .:ol;.                 .';.
                                ..              .cO00k:.                  .,.
                               ..          .'...;k00Od'                   .'.
                              ...        .;xOkxdk00Od,                    ...
                             ...        .,x0000000Od;.                     ..
                             .'         .cO00OOOOOOd;'...                 ...
                            .'.          .;lxkOOOO00Okkxo:.               .'.
                           .'.             .cxOOOOO000000Ol.              .'.
                          .'.             .ck00OOd::oxOOOOl.              .,.
                          ''...,;''''''''':kKK0Od,. ..:xOo'               .,.
                         ';,;;;:,..........;lxOx:.    .';'               .''
                        'cc;..               .,;:,..                     ...
                       ,oc.       ..........    .',:;,..                 ...
                      'o:.     .,;;;,,,,;;;;;'.    ..,;;,..              ...
                      ';.      ...         .,::.       .,::'.            .'.
                      ..                     .',.        ..;;'.         ...
                     ..          .',,;;,'.                  ':;'.       .,.
                    .,::;,.        .......                   .';:'.    .,,.
                    .;dOK0x;.                         .        .':;.   .,.
                    ...,cdxdl;.              ..,;;;cloddoc;.     .,:,. .,.
                   .     ...;cl:.          ':ldxxdocccclol;.      ..:;.',.
                   .   .;llc;',c;.       .,:,''';::;'.  ..          .;:;'
                      .:xdoxko,',.      .,:. .;llc:ldl.              .;c.
                      .lxdoxkd:''.     .;:.  .cxl'';od;.          .. .,,
                      .:clool;.',.     .:'   .:dxolccl;.         .::;,:'
                       .;::,.. .,.     .;.   .,:;:;,,;'         .,;,:ol.
                         ..    ',.     .;.    .',,,,,.          .,:llc;.
                              .,'      .,.                      .;lxxc'
                             .,;.      .;.                      .;lxxc.
            ..              .;;.       .:'                      .;cc,.
           ...';'          .;;.        .;:.                      ,:'
          .;c:;.       .. .,;.       ....,;.                     .'.
         .,lc,.      .':,..,:,''....;c:;'':'..              ..   .'.
         .;:;.      .,:'   .::,,;;;;;..',;,..,,.            .,.  .'.
        .'',,.     .,;.                      .;,            .'.  ...
        .'',,.    .,;.                        ';.           .,.  .'.
        .'...     .;.                         .,,.          .,'   ..
        .'.      .;,.                          .::.         .,'   .
        .'.     .,;.                            ,c'         .,'  .'.
        .'.     .:'                             .,'          .. .,'
         ''.    ,;.    .....................    .;'            .:,
         .,.   .,;.   ..'''''''''''''''''','.  .,;.           .::.
          .,.   ,;.                           .,;.           .;,.
          .,,.  .:,.                         .;;.          .''.
           .,'   .'.                         ...          .,.
            .''                                          .,.
             .,'.                                       .'.
              .'.                                      .*/

#include <fstream>

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <set>
#include <map>

#define ll long long
#define ld long double
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define all(v) v.begin(), v.end()
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")

using namespace std;

template<typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
    _out << _p.first << ' ' << _p.second;
    return _out;
}

template<typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
    _in >> _p.first >> _p.second;
    return _in;
}

template<typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
    if (_v.empty()) { return _out; }
    _out << _v.front();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}

template<typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}

const int MAXN = 2e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

vc<pr<pr<int, int>, pr<int, int>>> lefts, rights;


void add_segment(int l1, int r1, int l2, int r2, int value) {
    //cout << l1 << ' ' << r1 << ' ' << l2 << ' ' << r2 << ' ' << value << endl;
    if (r1 - l1 <= r2 - l2) {
        for (int i = l1; i <= r1; i++) {
            lefts.pb({{i,      value},
                      {l2 - i, r2 - i}});
        }
    } else {
        for (int i = l2; i <= r2; i++) {
            rights.pb({{i,      value},
                       {i - r1, i - l1}});
        }
    }
}

int n;
ll t[MAXN];

void init(int nn) {
    n = nn;
    fill(t, t + n, 0);
}

void upd(int v, int x) {
    for (; v < n; v = (v | (v + 1))) {
        t[v] += x;
    }
}

ll get(int v) {
    ll ans = 0;
    for (; v >= 0; v = (v & (v + 1)) - 1) {
        ans += t[v];
    }
    return ans;
}

ll get(int l, int r) {
    return get(r) - get(l - 1);
}

class pozhar {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, q;
        in >> n >> q;
        vc<int> s(n);
        in >> s;
        set<int> limiters;
        limiters.insert(-1);
        limiters.insert(n);
        vc<pr<int, int>> dds;
        for (int i = 0; i < n; i++) {
            dds.pb({s[i], i});
        }
        sort(all(dds));
        reverse(all(dds));
        for (auto v : dds) {
            auto r = (*limiters.lower_bound(v.sc)) - 1;
            auto l = (*prev(limiters.lower_bound(v.sc))) + 1;
            if (l <= v.sc && v.sc <= r) {
                add_segment(l, v.sc, v.sc, r, v.fs);
            }
            limiters.insert(v.sc);
        }
        /*
        cout << "lefts\n";
        for (auto v : lefts) {
            cout << v << endl;
        }
        cout << "rights\n";
        for (auto v : rights) {
            cout << v << endl;
        }
         */
        vc<ll> ans(q);
        vc<pr<int, pr<int, int>>> que(q);
        vc<vc<int>> bylen(n + 2);
        int i = 0;
        for (auto &v : que) {
            in >> v.fs >> v.sc;
            v.sc.fs--, v.sc.sc--;
            bylen[v.fs].pb(i);
            i++;
        }
        {
            int maxi = 0;
            for (int i = 0; i < n; i++) {
                maxi = max(maxi, s[i]);
                rights.pb({{i,     maxi},
                           {i + 1, n}});
            }
        }
        {
            vc<vc<pr<int, int>>> gr(n + 2);
            for (auto v : lefts) {
                gr[v.sc.fs].pb(v.fs);
                v.fs.sc *= -1;
                gr[v.sc.sc + 1].pb(v.fs);
            }
            init(n + 10);
            for (int i = 0; i <= n; i++) {
                for (auto d : gr[i]) {
                    upd(d.fs, d.sc);
                }
                for (auto d : bylen[i]) {
                    ans[d] += get(que[d].sc.fs - i, que[d].sc.sc - i);
                }
            }
        }
        {
            vc<vc<pr<int, int>>> gr(n + 2);
            for (auto v : rights) {
                gr[v.sc.fs].pb(v.fs);
                v.fs.sc *= -1;
                gr[v.sc.sc + 1].pb(v.fs);
            }
            init(n + 10);
            for (int i = 0; i <= n; i++) {
                for (auto d : gr[i]) {
                    upd(d.fs, d.sc);
                }
                for (auto d : bylen[i]) {
                    ans[d] += get(que[d].sc.fs, que[d].sc.sc);
                }
            }
        }
        for (auto v : ans) {
            out << v << '\n';
        }
    }
};


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	pozhar solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 520 ms 69152 KB Output is correct
3 Correct 508 ms 69020 KB Output is correct
4 Correct 510 ms 69408 KB Output is correct
5 Correct 528 ms 71584 KB Output is correct
6 Correct 517 ms 73448 KB Output is correct
7 Correct 534 ms 70420 KB Output is correct
8 Correct 575 ms 75540 KB Output is correct
9 Correct 542 ms 70944 KB Output is correct
10 Correct 524 ms 68252 KB Output is correct
11 Correct 552 ms 76244 KB Output is correct
12 Correct 560 ms 70144 KB Output is correct
13 Correct 541 ms 70828 KB Output is correct
14 Correct 557 ms 72824 KB Output is correct
15 Correct 538 ms 68856 KB Output is correct
16 Correct 549 ms 71132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 670 ms 72876 KB Output is correct
3 Correct 636 ms 70884 KB Output is correct
4 Correct 658 ms 76960 KB Output is correct
5 Correct 669 ms 73376 KB Output is correct
6 Correct 646 ms 73368 KB Output is correct
7 Correct 655 ms 75556 KB Output is correct
8 Correct 645 ms 74016 KB Output is correct
9 Correct 616 ms 71968 KB Output is correct
10 Correct 642 ms 74144 KB Output is correct
11 Correct 658 ms 75256 KB Output is correct
12 Correct 653 ms 73956 KB Output is correct
13 Correct 671 ms 72880 KB Output is correct
14 Correct 613 ms 71892 KB Output is correct
15 Correct 711 ms 74272 KB Output is correct
16 Correct 659 ms 72248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 49468 KB Output is correct
2 Correct 384 ms 50064 KB Output is correct
3 Correct 387 ms 51108 KB Output is correct
4 Correct 377 ms 49124 KB Output is correct
5 Correct 374 ms 49980 KB Output is correct
6 Correct 402 ms 49908 KB Output is correct
7 Correct 396 ms 50984 KB Output is correct
8 Correct 423 ms 50536 KB Output is correct
9 Correct 390 ms 49596 KB Output is correct
10 Correct 391 ms 50392 KB Output is correct
11 Correct 389 ms 49836 KB Output is correct
12 Correct 378 ms 49936 KB Output is correct
13 Correct 393 ms 49956 KB Output is correct
14 Correct 385 ms 50200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 633 ms 73852 KB Output is correct
34 Correct 661 ms 76680 KB Output is correct
35 Correct 641 ms 75412 KB Output is correct
36 Correct 644 ms 75492 KB Output is correct
37 Correct 629 ms 71876 KB Output is correct
38 Correct 630 ms 71996 KB Output is correct
39 Correct 621 ms 73116 KB Output is correct
40 Correct 612 ms 72616 KB Output is correct
41 Correct 638 ms 73852 KB Output is correct
42 Correct 631 ms 74796 KB Output is correct
43 Correct 588 ms 76064 KB Output is correct
44 Correct 545 ms 70608 KB Output is correct
45 Correct 535 ms 67868 KB Output is correct
46 Correct 562 ms 71048 KB Output is correct
47 Correct 540 ms 69844 KB Output is correct
48 Correct 528 ms 71088 KB Output is correct
49 Correct 534 ms 71908 KB Output is correct
50 Correct 565 ms 71332 KB Output is correct
51 Correct 567 ms 70264 KB Output is correct
52 Correct 553 ms 71528 KB Output is correct
53 Correct 534 ms 68256 KB Output is correct
54 Correct 553 ms 68348 KB Output is correct
55 Correct 574 ms 72284 KB Output is correct
56 Correct 579 ms 71100 KB Output is correct
57 Correct 560 ms 69696 KB Output is correct
58 Correct 591 ms 71404 KB Output is correct
59 Correct 520 ms 69152 KB Output is correct
60 Correct 508 ms 69020 KB Output is correct
61 Correct 510 ms 69408 KB Output is correct
62 Correct 528 ms 71584 KB Output is correct
63 Correct 517 ms 73448 KB Output is correct
64 Correct 534 ms 70420 KB Output is correct
65 Correct 575 ms 75540 KB Output is correct
66 Correct 542 ms 70944 KB Output is correct
67 Correct 524 ms 68252 KB Output is correct
68 Correct 552 ms 76244 KB Output is correct
69 Correct 560 ms 70144 KB Output is correct
70 Correct 541 ms 70828 KB Output is correct
71 Correct 557 ms 72824 KB Output is correct
72 Correct 538 ms 68856 KB Output is correct
73 Correct 549 ms 71132 KB Output is correct
74 Correct 670 ms 72876 KB Output is correct
75 Correct 636 ms 70884 KB Output is correct
76 Correct 658 ms 76960 KB Output is correct
77 Correct 669 ms 73376 KB Output is correct
78 Correct 646 ms 73368 KB Output is correct
79 Correct 655 ms 75556 KB Output is correct
80 Correct 645 ms 74016 KB Output is correct
81 Correct 616 ms 71968 KB Output is correct
82 Correct 642 ms 74144 KB Output is correct
83 Correct 658 ms 75256 KB Output is correct
84 Correct 653 ms 73956 KB Output is correct
85 Correct 671 ms 72880 KB Output is correct
86 Correct 613 ms 71892 KB Output is correct
87 Correct 711 ms 74272 KB Output is correct
88 Correct 659 ms 72248 KB Output is correct
89 Correct 377 ms 49468 KB Output is correct
90 Correct 384 ms 50064 KB Output is correct
91 Correct 387 ms 51108 KB Output is correct
92 Correct 377 ms 49124 KB Output is correct
93 Correct 374 ms 49980 KB Output is correct
94 Correct 402 ms 49908 KB Output is correct
95 Correct 396 ms 50984 KB Output is correct
96 Correct 423 ms 50536 KB Output is correct
97 Correct 390 ms 49596 KB Output is correct
98 Correct 391 ms 50392 KB Output is correct
99 Correct 389 ms 49836 KB Output is correct
100 Correct 378 ms 49936 KB Output is correct
101 Correct 393 ms 49956 KB Output is correct
102 Correct 385 ms 50200 KB Output is correct