Submission #531202

# Submission time Handle Problem Language Result Execution time Memory
531202 2022-02-28T04:48:46 Z Killer2501 Fire (JOI20_ho_t5) C++17
14 / 100
426 ms 262148 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, ll>
#define fi first
#define se second
using namespace std;
const int N = 2e5+5;
const int M = 250;
const int mod = 1e9+7;
const ll base = 75;
const ll inf = 1e16;
ll n, t, lab[N], c[N], b[N], a[N];
ll ans, tong, d[N], l[N], r[N], fe[N];
ll m, k;
vector<pii> adj[N], radj[N];
vector<int> vi, ask[N];
string s, res;
struct node
{
    int l, r, t;
}q[N];
void add(int id, ll x)
{
    assert(id > 0);
    for(; id <= n; id += id & -id)fe[id] += x;
}
ll get(int id)
{
    ll total = 0;
    if(id <= 0)return total;
    for(; id; id -= id & -id)total += fe[id];
    return total;
}
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        while(!vi.empty() && a[i] >= a[vi.back()])vi.pop_back();
        l[i] = vi.empty() ? 0 : vi.back();
        vi.pb(i);
    }
    vi.clear();
    for(int i = n; i > 0; i --)
    {
        while(!vi.empty() && a[i] >= a[vi.back()])vi.pop_back();
        r[i] = vi.empty() ? n+1 : vi.back();
        vi.pb(i);
    }
    for(int i = 1; i <= n; i ++)
    {
        //cout << l[i] <<" "<<r[i] << '\n';
        if(!l[i] || i-l[i] > r[i]-i)
        {
            for(int j = i; j < r[i]; j ++)
            {
                adj[j-i].pb({j, a[i]});
                if(l[i])adj[j-l[i]].pb({j, -a[i]});
            }
        }
        else
        {
            for(int j = i; j > l[i]; j --)
            {
                radj[i-j].pb({j, a[i]});
                if(r[i] <= n)radj[r[i]-j].pb({j, -a[i]});
            }
        }
    }
    for(int i = 1; i <= m; i ++)
    {
        cin >> q[i].t >> q[i].l >> q[i].r;
        ask[q[i].t].pb(i);
    }
    for(int i = 0; i <= n; i ++)
    {
        for(pii j: adj[i])add(j.fi, j.se);
        for(int j: ask[i])d[j] += get(q[j].r)-get(q[j].l-1);
    }
    fill_n(fe, n+1, 0);
    for(int i = 0; i <= n; i ++)
    {
        for(pii j: radj[i])add(j.fi, j.se);
        for(int j: ask[i])d[j] += get(q[j].r-i) - get(q[j].l-i-1);
    }
    for(int i = 1; i <= m; i ++)cout << d[i] << '\n';
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
    //cin >> test;
    while(test -- > 0)sol();
    return 0;
}

Compilation message

ho_t5.cpp: In function 'int main()':
ho_t5.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t5.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 12 ms 14412 KB Output is correct
3 Correct 9 ms 14412 KB Output is correct
4 Correct 8 ms 14444 KB Output is correct
5 Correct 10 ms 14412 KB Output is correct
6 Correct 9 ms 14432 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 9 ms 14452 KB Output is correct
9 Correct 8 ms 14412 KB Output is correct
10 Correct 8 ms 14456 KB Output is correct
11 Correct 8 ms 14412 KB Output is correct
12 Correct 8 ms 14412 KB Output is correct
13 Correct 8 ms 14412 KB Output is correct
14 Correct 8 ms 14412 KB Output is correct
15 Correct 8 ms 14412 KB Output is correct
16 Correct 9 ms 14452 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 10 ms 14424 KB Output is correct
19 Correct 8 ms 14412 KB Output is correct
20 Correct 10 ms 14412 KB Output is correct
21 Correct 9 ms 14416 KB Output is correct
22 Correct 9 ms 14484 KB Output is correct
23 Correct 11 ms 14412 KB Output is correct
24 Correct 8 ms 14496 KB Output is correct
25 Correct 7 ms 14432 KB Output is correct
26 Correct 9 ms 14412 KB Output is correct
27 Correct 9 ms 14412 KB Output is correct
28 Correct 10 ms 14404 KB Output is correct
29 Correct 8 ms 14464 KB Output is correct
30 Correct 10 ms 14412 KB Output is correct
31 Correct 8 ms 14412 KB Output is correct
32 Correct 11 ms 14412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 241 ms 81436 KB Output is correct
3 Correct 282 ms 87096 KB Output is correct
4 Correct 244 ms 82852 KB Output is correct
5 Correct 256 ms 85984 KB Output is correct
6 Correct 251 ms 84488 KB Output is correct
7 Correct 285 ms 83216 KB Output is correct
8 Correct 254 ms 86048 KB Output is correct
9 Correct 248 ms 84892 KB Output is correct
10 Correct 261 ms 81644 KB Output is correct
11 Correct 276 ms 82144 KB Output is correct
12 Correct 255 ms 81868 KB Output is correct
13 Correct 282 ms 83492 KB Output is correct
14 Correct 238 ms 84316 KB Output is correct
15 Correct 284 ms 85120 KB Output is correct
16 Correct 272 ms 88484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 320 ms 87488 KB Output is correct
3 Correct 311 ms 82864 KB Output is correct
4 Correct 336 ms 92128 KB Output is correct
5 Correct 385 ms 82632 KB Output is correct
6 Correct 377 ms 84176 KB Output is correct
7 Correct 311 ms 84004 KB Output is correct
8 Correct 306 ms 84768 KB Output is correct
9 Correct 298 ms 83144 KB Output is correct
10 Correct 321 ms 85916 KB Output is correct
11 Correct 315 ms 89580 KB Output is correct
12 Correct 311 ms 86072 KB Output is correct
13 Correct 304 ms 88100 KB Output is correct
14 Correct 300 ms 80996 KB Output is correct
15 Correct 357 ms 87044 KB Output is correct
16 Correct 397 ms 86988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 426 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 12 ms 14412 KB Output is correct
3 Correct 9 ms 14412 KB Output is correct
4 Correct 8 ms 14444 KB Output is correct
5 Correct 10 ms 14412 KB Output is correct
6 Correct 9 ms 14432 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 9 ms 14452 KB Output is correct
9 Correct 8 ms 14412 KB Output is correct
10 Correct 8 ms 14456 KB Output is correct
11 Correct 8 ms 14412 KB Output is correct
12 Correct 8 ms 14412 KB Output is correct
13 Correct 8 ms 14412 KB Output is correct
14 Correct 8 ms 14412 KB Output is correct
15 Correct 8 ms 14412 KB Output is correct
16 Correct 9 ms 14452 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 10 ms 14424 KB Output is correct
19 Correct 8 ms 14412 KB Output is correct
20 Correct 10 ms 14412 KB Output is correct
21 Correct 9 ms 14416 KB Output is correct
22 Correct 9 ms 14484 KB Output is correct
23 Correct 11 ms 14412 KB Output is correct
24 Correct 8 ms 14496 KB Output is correct
25 Correct 7 ms 14432 KB Output is correct
26 Correct 9 ms 14412 KB Output is correct
27 Correct 9 ms 14412 KB Output is correct
28 Correct 10 ms 14404 KB Output is correct
29 Correct 8 ms 14464 KB Output is correct
30 Correct 10 ms 14412 KB Output is correct
31 Correct 8 ms 14412 KB Output is correct
32 Correct 11 ms 14412 KB Output is correct
33 Correct 241 ms 81436 KB Output is correct
34 Correct 282 ms 87096 KB Output is correct
35 Correct 244 ms 82852 KB Output is correct
36 Correct 256 ms 85984 KB Output is correct
37 Correct 251 ms 84488 KB Output is correct
38 Correct 285 ms 83216 KB Output is correct
39 Correct 254 ms 86048 KB Output is correct
40 Correct 248 ms 84892 KB Output is correct
41 Correct 261 ms 81644 KB Output is correct
42 Correct 276 ms 82144 KB Output is correct
43 Correct 255 ms 81868 KB Output is correct
44 Correct 282 ms 83492 KB Output is correct
45 Correct 238 ms 84316 KB Output is correct
46 Correct 284 ms 85120 KB Output is correct
47 Correct 272 ms 88484 KB Output is correct
48 Correct 320 ms 87488 KB Output is correct
49 Correct 311 ms 82864 KB Output is correct
50 Correct 336 ms 92128 KB Output is correct
51 Correct 385 ms 82632 KB Output is correct
52 Correct 377 ms 84176 KB Output is correct
53 Correct 311 ms 84004 KB Output is correct
54 Correct 306 ms 84768 KB Output is correct
55 Correct 298 ms 83144 KB Output is correct
56 Correct 321 ms 85916 KB Output is correct
57 Correct 315 ms 89580 KB Output is correct
58 Correct 311 ms 86072 KB Output is correct
59 Correct 304 ms 88100 KB Output is correct
60 Correct 300 ms 80996 KB Output is correct
61 Correct 357 ms 87044 KB Output is correct
62 Correct 397 ms 86988 KB Output is correct
63 Runtime error 426 ms 262148 KB Execution killed with signal 9
64 Halted 0 ms 0 KB -