답안 #531187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531187 2022-02-28T04:09:47 Z Killer2501 Fire (JOI20_ho_t5) C++14
14 / 100
420 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)
{
    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:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 8 ms 14412 KB Output is correct
3 Correct 7 ms 14412 KB Output is correct
4 Correct 8 ms 14380 KB Output is correct
5 Correct 10 ms 14420 KB Output is correct
6 Correct 8 ms 14412 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 8 ms 14412 KB Output is correct
9 Correct 7 ms 14412 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 7 ms 14412 KB Output is correct
12 Correct 7 ms 14412 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14412 KB Output is correct
15 Correct 8 ms 14412 KB Output is correct
16 Correct 7 ms 14476 KB Output is correct
17 Correct 8 ms 14412 KB Output is correct
18 Correct 7 ms 14412 KB Output is correct
19 Correct 10 ms 14500 KB Output is correct
20 Correct 7 ms 14424 KB Output is correct
21 Correct 7 ms 14412 KB Output is correct
22 Correct 9 ms 14476 KB Output is correct
23 Correct 8 ms 14416 KB Output is correct
24 Correct 8 ms 14388 KB Output is correct
25 Correct 7 ms 14412 KB Output is correct
26 Correct 7 ms 14412 KB Output is correct
27 Correct 8 ms 14376 KB Output is correct
28 Correct 7 ms 14376 KB Output is correct
29 Correct 7 ms 14412 KB Output is correct
30 Correct 7 ms 14464 KB Output is correct
31 Correct 8 ms 14412 KB Output is correct
32 Correct 8 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 242 ms 81524 KB Output is correct
3 Correct 269 ms 87132 KB Output is correct
4 Correct 234 ms 82888 KB Output is correct
5 Correct 246 ms 86008 KB Output is correct
6 Correct 243 ms 84512 KB Output is correct
7 Correct 250 ms 83196 KB Output is correct
8 Correct 236 ms 85968 KB Output is correct
9 Correct 237 ms 84888 KB Output is correct
10 Correct 241 ms 81700 KB Output is correct
11 Correct 227 ms 82204 KB Output is correct
12 Correct 254 ms 81932 KB Output is correct
13 Correct 264 ms 83504 KB Output is correct
14 Correct 238 ms 84468 KB Output is correct
15 Correct 238 ms 85196 KB Output is correct
16 Correct 266 ms 88548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 358 ms 87472 KB Output is correct
3 Correct 319 ms 82968 KB Output is correct
4 Correct 336 ms 92088 KB Output is correct
5 Correct 292 ms 82724 KB Output is correct
6 Correct 365 ms 84272 KB Output is correct
7 Correct 324 ms 84016 KB Output is correct
8 Correct 314 ms 84668 KB Output is correct
9 Correct 325 ms 83216 KB Output is correct
10 Correct 355 ms 85884 KB Output is correct
11 Correct 355 ms 89552 KB Output is correct
12 Correct 306 ms 85944 KB Output is correct
13 Correct 333 ms 88128 KB Output is correct
14 Correct 315 ms 81036 KB Output is correct
15 Correct 356 ms 87052 KB Output is correct
16 Correct 339 ms 86964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 420 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 8 ms 14412 KB Output is correct
3 Correct 7 ms 14412 KB Output is correct
4 Correct 8 ms 14380 KB Output is correct
5 Correct 10 ms 14420 KB Output is correct
6 Correct 8 ms 14412 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 8 ms 14412 KB Output is correct
9 Correct 7 ms 14412 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 7 ms 14412 KB Output is correct
12 Correct 7 ms 14412 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14412 KB Output is correct
15 Correct 8 ms 14412 KB Output is correct
16 Correct 7 ms 14476 KB Output is correct
17 Correct 8 ms 14412 KB Output is correct
18 Correct 7 ms 14412 KB Output is correct
19 Correct 10 ms 14500 KB Output is correct
20 Correct 7 ms 14424 KB Output is correct
21 Correct 7 ms 14412 KB Output is correct
22 Correct 9 ms 14476 KB Output is correct
23 Correct 8 ms 14416 KB Output is correct
24 Correct 8 ms 14388 KB Output is correct
25 Correct 7 ms 14412 KB Output is correct
26 Correct 7 ms 14412 KB Output is correct
27 Correct 8 ms 14376 KB Output is correct
28 Correct 7 ms 14376 KB Output is correct
29 Correct 7 ms 14412 KB Output is correct
30 Correct 7 ms 14464 KB Output is correct
31 Correct 8 ms 14412 KB Output is correct
32 Correct 8 ms 14416 KB Output is correct
33 Correct 242 ms 81524 KB Output is correct
34 Correct 269 ms 87132 KB Output is correct
35 Correct 234 ms 82888 KB Output is correct
36 Correct 246 ms 86008 KB Output is correct
37 Correct 243 ms 84512 KB Output is correct
38 Correct 250 ms 83196 KB Output is correct
39 Correct 236 ms 85968 KB Output is correct
40 Correct 237 ms 84888 KB Output is correct
41 Correct 241 ms 81700 KB Output is correct
42 Correct 227 ms 82204 KB Output is correct
43 Correct 254 ms 81932 KB Output is correct
44 Correct 264 ms 83504 KB Output is correct
45 Correct 238 ms 84468 KB Output is correct
46 Correct 238 ms 85196 KB Output is correct
47 Correct 266 ms 88548 KB Output is correct
48 Correct 358 ms 87472 KB Output is correct
49 Correct 319 ms 82968 KB Output is correct
50 Correct 336 ms 92088 KB Output is correct
51 Correct 292 ms 82724 KB Output is correct
52 Correct 365 ms 84272 KB Output is correct
53 Correct 324 ms 84016 KB Output is correct
54 Correct 314 ms 84668 KB Output is correct
55 Correct 325 ms 83216 KB Output is correct
56 Correct 355 ms 85884 KB Output is correct
57 Correct 355 ms 89552 KB Output is correct
58 Correct 306 ms 85944 KB Output is correct
59 Correct 333 ms 88128 KB Output is correct
60 Correct 315 ms 81036 KB Output is correct
61 Correct 356 ms 87052 KB Output is correct
62 Correct 339 ms 86964 KB Output is correct
63 Runtime error 420 ms 262148 KB Execution killed with signal 9
64 Halted 0 ms 0 KB -