Submission #246427

# Submission time Handle Problem Language Result Execution time Memory
246427 2020-07-09T09:33:23 Z sealnot123 Two Dishes (JOI19_dishes) C++17
0 / 100
392 ms 21240 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){
        if(S[i] < A[i]) continue;
        pillar_A[i] = upper_bound(B+1, B+1+m, S[i]-A[i]) - B;
        rmv[pillar_A[i]].pb(i);
        add(0, i+1, 1, n+1);
        add(1, i+1, 1, n+1);
    }
    FOR(i, 1, m){
        if(T[i] < B[i]) continue;
        pillar_B[i] = upper_bound(A+1, A+1+n, T[i]-B[i]) - A - 1;
        // 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);
        for(int e : rmv[i]) add(1, e+1, -1, n+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 392 ms 21240 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 7 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 Incorrect 8 ms 5120 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 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 Incorrect 8 ms 5120 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 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 Incorrect 8 ms 5120 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 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 Incorrect 8 ms 5120 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 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 Incorrect 8 ms 5120 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 392 ms 21240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 392 ms 21240 KB Output isn't correct
2 Halted 0 ms 0 KB -