Submission #534994

# Submission time Handle Problem Language Result Execution time Memory
534994 2022-03-09T08:55:10 Z Killer2501 Self Study (JOI22_ho_t2) C++14
62 / 100
138 ms 17660 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pll pair<ll, int>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 3e5+5;
const int M = 8;
const int mod = 998244353;
const int base = 350;
const ll inf = 1e15+7;
int m, n, k, t, c[N],  d[N], dp[N][3], L, R, in[N], out[N], pos[N];
ll ans, tong, b[N], a[N];
vector<int> adj[N];
string s;
int r, sz, ntime;
struct BIT
{
    int n;
    vector<int> fe;
    BIT(){}
    void init(int _n)
    {
        n = _n;
        fe.assign(n+1, 0);
    }
    void add(int id, int x)
    {
        ++id;
        for(; id <= n; id += id & -id)fe[id] += x;
    }
    int get(int id)
    {
        ++id;
        id = min(id, n);
        if(id <= 0)return 0;
        int total = 0;
        for(; id; id -= id & -id)total += fe[id];
        return total;
    }
    int get(int l, int r)
    {
        return get(r) - get(l-1);
    }
}bit[3];
void dfs(int u, int p = 0)
{
    int mx = 0;
    d[u] = 1;
    for(int v: adj[u])
    {
        if(v == p || b[v])continue;
        dfs(v, u);
        d[u] += d[v];
        mx = max(d[v], mx);
    }
    mx = max(mx, sz-d[u]);
    if(mx*2 <= sz)r = u;
}
void cal(int u,  int p = 0)
{
    if(L <= c[u] && c[u] <= R)++ans;
    in[u] = ++ntime;
    pos[ntime] = u;
    for(int v: adj[u])
    {
        if(v == p || b[v])continue;
        c[v] = c[u];
        if(p && a[u] > a[p] && a[u] > a[v])++c[v];
        cal(v, u);
    }
    out[u] = ntime;
}
void decom(int u)
{
    //cout << u << endl;
    int all = sz;
    b[u] = 1;
    ntime = 0;
    c[u] = 0;
    cal(u);
    //cout << u << '\n';
    //for(int j = in[u]; j <= out[u]; j ++)cout << pos[j] <<" "<< c[pos[j]] << '\n';
    for(int v: adj[u])
    {
        if(b[v])continue;
        if(a[v] < a[u])
        {
            for(int j = in[v]; j <= out[v]; j ++)
            {
                int x = pos[j];
                ans += bit[0].get(L-c[x], R-c[x]);
                ans += bit[1].get(L-c[x]-1, R-c[x]-1);
            }
            for(int j = in[v]; j <= out[v]; j ++)
            {
                int x = pos[j];
                bit[1].add(c[x], 1);
            }
        }
        else
        {
            for(int j = in[v]; j <= out[v]; j ++)
            {
                int x = pos[j];
                ans += bit[0].get(L-c[x], R-c[x]);
                ans += bit[1].get(L-c[x], R-c[x]);
            }
            for(int j = in[v]; j <= out[v]; j ++)
            {
                int x = pos[j];
                bit[0].add(c[x], 1);
            }
        }
    }
    for(int v: adj[u])
    {
        if(b[v])continue;
        if(a[v] < a[u])
        {
            for(int j = in[v]; j <= out[v]; j ++)
            {
                int x = pos[j];
                bit[1].add(c[x], -1);
            }
        }
        else
        {
            for(int j = in[v]; j <= out[v]; j ++)
            {
                int x = pos[j];
                bit[0].add(c[x], -1);
            }
        }
    }
    for(int v: adj[u])
    {
        if(b[v])continue;
        sz = d[v] > d[u] ? all-d[u] : d[v];
        dfs(v);
        decom(r);
    }
}
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)cin >> a[i];
    for(int i = 1; i <= n; i ++)cin >> b[i];
    ll l = 1, r = inf, mid;
    while(l <= r)
    {
        mid = (l+r)>>1;
        ll need = 0, have = 0;
        for(int i = 1; i <= n; i ++)
        {
            if(a[i] >= b[i])
            {
                if(a[i]*m >= mid)have += m-(mid+a[i]-1)/a[i];
                else need += (mid-a[i]*m+b[i]-1)/b[i];
            }
            else
            {
                if(b[i]*m >= mid)have += m-(mid+b[i]-1)/b[i];
                else need += (mid-b[i]*m+b[i]-1)/b[i];
            }
            if(need > n*m)break;
        }
        if(have >= need)l = mid+1;
        else r = mid-1;
    }
    cout << r;
}
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

Main.cpp: In function 'int main()':
Main.cpp:184:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  184 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:185:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  185 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7324 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 5 ms 7372 KB Output is correct
10 Correct 6 ms 7516 KB Output is correct
11 Correct 115 ms 17660 KB Output is correct
12 Correct 120 ms 17604 KB Output is correct
13 Correct 112 ms 15864 KB Output is correct
14 Correct 93 ms 15928 KB Output is correct
15 Correct 4 ms 7368 KB Output is correct
16 Correct 42 ms 13132 KB Output is correct
17 Correct 138 ms 17608 KB Output is correct
18 Correct 110 ms 17604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7368 KB Output is correct
2 Correct 42 ms 13132 KB Output is correct
3 Correct 138 ms 17608 KB Output is correct
4 Correct 110 ms 17604 KB Output is correct
5 Correct 6 ms 7376 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 4 ms 7368 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7368 KB Output is correct
11 Correct 5 ms 7372 KB Output is correct
12 Correct 4 ms 7372 KB Output is correct
13 Correct 56 ms 12488 KB Output is correct
14 Correct 37 ms 10740 KB Output is correct
15 Correct 31 ms 9936 KB Output is correct
16 Correct 28 ms 9520 KB Output is correct
17 Correct 5 ms 7380 KB Output is correct
18 Correct 4 ms 7372 KB Output is correct
19 Correct 5 ms 7372 KB Output is correct
20 Correct 4 ms 7372 KB Output is correct
21 Correct 6 ms 7392 KB Output is correct
22 Correct 4 ms 7372 KB Output is correct
23 Correct 6 ms 7504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7324 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 5 ms 7372 KB Output is correct
10 Correct 6 ms 7516 KB Output is correct
11 Correct 115 ms 17660 KB Output is correct
12 Correct 120 ms 17604 KB Output is correct
13 Correct 112 ms 15864 KB Output is correct
14 Correct 93 ms 15928 KB Output is correct
15 Correct 6 ms 7376 KB Output is correct
16 Correct 4 ms 7372 KB Output is correct
17 Correct 4 ms 7368 KB Output is correct
18 Correct 4 ms 7372 KB Output is correct
19 Correct 4 ms 7372 KB Output is correct
20 Correct 4 ms 7368 KB Output is correct
21 Correct 5 ms 7372 KB Output is correct
22 Correct 4 ms 7372 KB Output is correct
23 Correct 56 ms 12488 KB Output is correct
24 Correct 37 ms 10740 KB Output is correct
25 Correct 31 ms 9936 KB Output is correct
26 Correct 28 ms 9520 KB Output is correct
27 Correct 5 ms 7380 KB Output is correct
28 Correct 4 ms 7372 KB Output is correct
29 Correct 5 ms 7372 KB Output is correct
30 Correct 4 ms 7372 KB Output is correct
31 Correct 6 ms 7392 KB Output is correct
32 Correct 4 ms 7372 KB Output is correct
33 Correct 6 ms 7504 KB Output is correct
34 Correct 4 ms 7368 KB Output is correct
35 Correct 42 ms 13132 KB Output is correct
36 Correct 138 ms 17608 KB Output is correct
37 Correct 110 ms 17604 KB Output is correct
38 Correct 4 ms 7368 KB Output is correct
39 Correct 4 ms 7372 KB Output is correct
40 Correct 4 ms 7380 KB Output is correct
41 Correct 4 ms 7372 KB Output is correct
42 Correct 4 ms 7372 KB Output is correct
43 Correct 5 ms 7372 KB Output is correct
44 Correct 4 ms 7372 KB Output is correct
45 Correct 8 ms 7576 KB Output is correct
46 Correct 8 ms 7568 KB Output is correct
47 Correct 5 ms 7384 KB Output is correct
48 Correct 25 ms 9156 KB Output is correct
49 Correct 4 ms 7372 KB Output is correct
50 Correct 5 ms 7372 KB Output is correct
51 Correct 6 ms 7500 KB Output is correct
52 Correct 4 ms 7372 KB Output is correct
53 Correct 4 ms 7372 KB Output is correct
54 Correct 4 ms 7372 KB Output is correct
55 Correct 60 ms 12484 KB Output is correct
56 Correct 40 ms 10176 KB Output is correct
57 Correct 32 ms 10144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7376 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7368 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7368 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 56 ms 12488 KB Output is correct
10 Correct 37 ms 10740 KB Output is correct
11 Correct 31 ms 9936 KB Output is correct
12 Correct 28 ms 9520 KB Output is correct
13 Correct 5 ms 7380 KB Output is correct
14 Correct 4 ms 7372 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 4 ms 7372 KB Output is correct
17 Correct 6 ms 7392 KB Output is correct
18 Correct 4 ms 7372 KB Output is correct
19 Correct 6 ms 7504 KB Output is correct
20 Correct 4 ms 7368 KB Output is correct
21 Correct 42 ms 13132 KB Output is correct
22 Correct 138 ms 17608 KB Output is correct
23 Correct 110 ms 17604 KB Output is correct
24 Incorrect 16 ms 8892 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7324 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 5 ms 7372 KB Output is correct
10 Correct 6 ms 7516 KB Output is correct
11 Correct 115 ms 17660 KB Output is correct
12 Correct 120 ms 17604 KB Output is correct
13 Correct 112 ms 15864 KB Output is correct
14 Correct 93 ms 15928 KB Output is correct
15 Correct 6 ms 7376 KB Output is correct
16 Correct 4 ms 7372 KB Output is correct
17 Correct 4 ms 7368 KB Output is correct
18 Correct 4 ms 7372 KB Output is correct
19 Correct 4 ms 7372 KB Output is correct
20 Correct 4 ms 7368 KB Output is correct
21 Correct 5 ms 7372 KB Output is correct
22 Correct 4 ms 7372 KB Output is correct
23 Correct 56 ms 12488 KB Output is correct
24 Correct 37 ms 10740 KB Output is correct
25 Correct 31 ms 9936 KB Output is correct
26 Correct 28 ms 9520 KB Output is correct
27 Correct 5 ms 7380 KB Output is correct
28 Correct 4 ms 7372 KB Output is correct
29 Correct 5 ms 7372 KB Output is correct
30 Correct 4 ms 7372 KB Output is correct
31 Correct 6 ms 7392 KB Output is correct
32 Correct 4 ms 7372 KB Output is correct
33 Correct 6 ms 7504 KB Output is correct
34 Correct 4 ms 7368 KB Output is correct
35 Correct 4 ms 7372 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 4 ms 7372 KB Output is correct
38 Correct 4 ms 7372 KB Output is correct
39 Correct 5 ms 7372 KB Output is correct
40 Correct 4 ms 7372 KB Output is correct
41 Correct 8 ms 7576 KB Output is correct
42 Correct 8 ms 7568 KB Output is correct
43 Correct 5 ms 7384 KB Output is correct
44 Correct 25 ms 9156 KB Output is correct
45 Correct 4 ms 7372 KB Output is correct
46 Correct 5 ms 7372 KB Output is correct
47 Correct 6 ms 7500 KB Output is correct
48 Correct 4 ms 7372 KB Output is correct
49 Correct 4 ms 7372 KB Output is correct
50 Correct 4 ms 7372 KB Output is correct
51 Correct 60 ms 12484 KB Output is correct
52 Correct 40 ms 10176 KB Output is correct
53 Correct 32 ms 10144 KB Output is correct
54 Incorrect 16 ms 8892 KB Output isn't correct
55 Halted 0 ms 0 KB -