Submission #246433

# Submission time Handle Problem Language Result Execution time Memory
246433 2020-07-09T09:45:54 Z sealnot123 Two Dishes (JOI19_dishes) C++17
49 / 100
571 ms 37496 KB
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const int N = 200005;
LL A[N], B[N];
LL S[N], T[N];
LL P[N], Q[N];

int pillar_A[N], pillar_B[N];
int fw[2][N];
vector<int> rmv[N]; // to remove
void add(int k, int i, int v, int n){
    while(i <= n) fw[k][i] += v, i += (i&-i);
}
int get(int k, int i){
    int ans = 0;
    while(i > 0) ans += fw[k][i], i -= (i&-i);
    return ans;
}
void print(int k, int n){
    printf("fenwick %d : ",k);
    FOR(i, 0, n) printf("%d ",get(k, i+1));
    printf("\n");
}
int main(){
    int n, m;
    scanf("%d %d",&n,&m);
    FOR(i, 1, n){
        scanf("%lld %lld %lld",&A[i],&S[i],&P[i]);
        A[i] += A[i-1];
    }
    FOR(i, 1, m){
        scanf("%lld %lld %lld",&B[i],&T[i],&Q[i]);
        B[i] += B[i-1];
    }

    FOR(i, 1, n){
        pillar_A[i] = upper_bound(B, B+1+m, S[i]-A[i]) - B;
        if(pillar_A[i] == 0) continue;
        rmv[pillar_A[i]].pb(i);
        add(0, i+1, 1, n+1);
        add(1, i+1, 1, n+1);
    }
    FOR(i, 1, m){
        for(int e : rmv[i]) add(1, e+1, -1, n+1);
        pillar_B[i] = upper_bound(A, A+1+n, T[i]-B[i]) - A - 1;
        if(pillar_B[i] == -1) continue;
        // iterate
        add(0, 1, 1, n+1);
        add(0, pillar_B[i]+2, -1, n+1);
        int pivot = pillar_B[i];
        int value = get(0, pivot+1);
        int l = pivot, r = n;
        // find the last point that it is higher
        while(l < r){
            int m = (l+r+1)>>1;
            if(value + get(1, m+1) - get(1, pivot+1) > get(0, m+1)) l = m;
            else r = m-1;
        }
        add(0, pivot+2, 1, n+1); add(0, l+2, -1, n+1);
        for(int e : rmv[i]){
            if(e < pivot+1 || e > l) continue;
            add(0, e+1, -1, n+1);
            add(0, l+2, 1, n+1);
        }
    }
    printf("%d",get(0, n+1));
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
dishes.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld",&A[i],&S[i],&P[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld",&B[i],&T[i],&Q[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 391 ms 21496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 9 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 9 ms 5120 KB Output is correct
17 Correct 9 ms 5248 KB Output is correct
18 Correct 10 ms 5376 KB Output is correct
19 Correct 11 ms 5376 KB Output is correct
20 Correct 10 ms 5248 KB Output is correct
21 Correct 10 ms 5376 KB Output is correct
22 Correct 10 ms 5248 KB Output is correct
23 Correct 10 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 9 ms 5120 KB Output is correct
17 Correct 9 ms 5248 KB Output is correct
18 Correct 10 ms 5376 KB Output is correct
19 Correct 11 ms 5376 KB Output is correct
20 Correct 10 ms 5248 KB Output is correct
21 Correct 10 ms 5376 KB Output is correct
22 Correct 10 ms 5248 KB Output is correct
23 Correct 10 ms 5248 KB Output is correct
24 Correct 238 ms 29036 KB Output is correct
25 Correct 305 ms 28656 KB Output is correct
26 Correct 254 ms 34556 KB Output is correct
27 Correct 406 ms 28780 KB Output is correct
28 Correct 312 ms 30192 KB Output is correct
29 Correct 225 ms 29780 KB Output is correct
30 Correct 571 ms 32112 KB Output is correct
31 Correct 109 ms 15736 KB Output is correct
32 Correct 120 ms 18284 KB Output is correct
33 Correct 368 ms 30328 KB Output is correct
34 Correct 424 ms 30452 KB Output is correct
35 Correct 464 ms 25944 KB Output is correct
36 Correct 438 ms 25788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 9 ms 5120 KB Output is correct
17 Correct 9 ms 5248 KB Output is correct
18 Correct 10 ms 5376 KB Output is correct
19 Correct 11 ms 5376 KB Output is correct
20 Correct 10 ms 5248 KB Output is correct
21 Correct 10 ms 5376 KB Output is correct
22 Correct 10 ms 5248 KB Output is correct
23 Correct 10 ms 5248 KB Output is correct
24 Correct 238 ms 29036 KB Output is correct
25 Correct 305 ms 28656 KB Output is correct
26 Correct 254 ms 34556 KB Output is correct
27 Correct 406 ms 28780 KB Output is correct
28 Correct 312 ms 30192 KB Output is correct
29 Correct 225 ms 29780 KB Output is correct
30 Correct 571 ms 32112 KB Output is correct
31 Correct 109 ms 15736 KB Output is correct
32 Correct 120 ms 18284 KB Output is correct
33 Correct 368 ms 30328 KB Output is correct
34 Correct 424 ms 30452 KB Output is correct
35 Correct 464 ms 25944 KB Output is correct
36 Correct 438 ms 25788 KB Output is correct
37 Incorrect 306 ms 37496 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 9 ms 5120 KB Output is correct
17 Correct 9 ms 5248 KB Output is correct
18 Correct 10 ms 5376 KB Output is correct
19 Correct 11 ms 5376 KB Output is correct
20 Correct 10 ms 5248 KB Output is correct
21 Correct 10 ms 5376 KB Output is correct
22 Correct 10 ms 5248 KB Output is correct
23 Correct 10 ms 5248 KB Output is correct
24 Correct 238 ms 29036 KB Output is correct
25 Correct 305 ms 28656 KB Output is correct
26 Correct 254 ms 34556 KB Output is correct
27 Correct 406 ms 28780 KB Output is correct
28 Correct 312 ms 30192 KB Output is correct
29 Correct 225 ms 29780 KB Output is correct
30 Correct 571 ms 32112 KB Output is correct
31 Correct 109 ms 15736 KB Output is correct
32 Correct 120 ms 18284 KB Output is correct
33 Correct 368 ms 30328 KB Output is correct
34 Correct 424 ms 30452 KB Output is correct
35 Correct 464 ms 25944 KB Output is correct
36 Correct 438 ms 25788 KB Output is correct
37 Incorrect 306 ms 37496 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 391 ms 21496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 391 ms 21496 KB Output isn't correct
2 Halted 0 ms 0 KB -