Submission #1090997

# Submission time Handle Problem Language Result Execution time Memory
1090997 2024-09-19T12:14:37 Z akim9905 Examination (JOI19_examination) C++17
0 / 100
377 ms 14904 KB
#include <bits/stdc++.h>
using namespace std;

#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;

const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 202020; // PLZ CHK!

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type, less<pii>, rb_tree_tag,tree_order_statistics_node_update>

typedef array<int,5> arr;

int N,Q;
vector<arr> A;
ll ans[MAX];

void dnc(int l, int r) {
    if (l==r) return;

    int m=(l+r)>>1;
    dnc(l,m), dnc(m+1,r);
    vector<arr> le,ri;
    for (int i=l; i<=m; i++) le.pb(A[i]);
    for (int i=m+1; i<=r; i++) ri.pb(A[i]);

    sort(all(le),[](auto a, auto b){
        if (a[1]==b[1]) return a[3]<b[3];
        return a[1]>b[1];
    });
    sort(all(ri),[](auto a, auto b){
        if (a[1]==b[1]) return a[3]<b[3];
        return a[1]>b[1];
    });

    ordered_set os;
    int i=0; 
    for (auto [x,y,z,q,idx]:ri) {
        while (i<sz(le) && le[i][1]>=y) {
            if (le[i][3]==0) os.insert({le[i][2],idx});
            i++;
        }

        if (q) {
            ll t=sz(os)-os.order_of_key({z,-INF*2});
            ans[idx]+=t;
        }
    }
}

int main() {
    fio();
    cin>>N>>Q;
    for (int i=0; i<N; i++) {
        int s,t; cin>>s>>t;
        A.pb({s,t,s+t,0,0});
    }
    for (int i=0; i<Q; i++) {
        int x,y,z; cin>>x>>y>>z;
        A.pb({x,y,z,1,i});
    }

    sort(all(A),[](auto a, auto b){
        if (a[0]==b[0]) return a[3]<b[3];
        return a[0]>b[0];
    });

    dnc(0,N+Q-1);

    for (int i=0; i<Q; i++) cout<<ans[i]<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 8 ms 900 KB Output is correct
8 Correct 8 ms 860 KB Output is correct
9 Correct 8 ms 860 KB Output is correct
10 Correct 7 ms 848 KB Output is correct
11 Correct 7 ms 828 KB Output is correct
12 Incorrect 5 ms 828 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 377 ms 14904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 377 ms 14904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 8 ms 900 KB Output is correct
8 Correct 8 ms 860 KB Output is correct
9 Correct 8 ms 860 KB Output is correct
10 Correct 7 ms 848 KB Output is correct
11 Correct 7 ms 828 KB Output is correct
12 Incorrect 5 ms 828 KB Output isn't correct
13 Halted 0 ms 0 KB -