답안 #784365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784365 2023-07-16T04:05:54 Z 1075508020060209tc 새 집 (APIO18_new_home) C++14
12 / 100
5000 ms 281812 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int n;
int K;int Q;
int xar[500005];
int typ[500005];
int ta[500005];
int tb[500005];
int qpl[500005];
int qt[500005];
int ans[500005];
void lisanhua(){
vector<int>vc;
for(int i=1;i<=n;i++){
    vc.push_back(ta[i]);
    vc.push_back(tb[i]);
}
for(int i=1;i<=Q;i++){
    vc.push_back(qt[i]);
}
sort(vc.begin(),vc.end());
for(int i=1;i<=n;i++){
    ta[i]=1+(lower_bound(vc.begin(),vc.end(),ta[i])-vc.begin());
    tb[i]=1+(lower_bound(vc.begin(),vc.end(),tb[i])-vc.begin());
}
for(int i=1;i<=Q;i++){
    qt[i]=1+(lower_bound(vc.begin(),vc.end(),qt[i])-vc.begin());
}
}
multiset<int>mst[510];
struct SGTR{
int l;int r;
vector<pair<int,int>>eve;
}tr[2000006];
void buildtr(int nw,int l,int r){
tr[nw].l=l;tr[nw].r=r;
if(l==r){return;}
int mi=(l+r)/2;
buildtr(nw*2,l,mi);
buildtr(nw*2+1,mi+1,r);
}

void upd(int nw,int l,int r,pair<int,int>shp){
if(tr[nw].l>=l&&tr[nw].r<=r){
    tr[nw].eve.push_back(shp);
    return;
}
if(tr[nw].r<l||tr[nw].l>r){
    return;
}
upd(nw*2,l,r,shp);
upd(nw*2+1,l,r,shp);
}
vector<int>fq[1000006];
void dfs(int nw){
for(int i=0;i<tr[nw].eve.size();i++){
    int tk=tr[nw].eve[i].second;
    int tpl=tr[nw].eve[i].first;
    mst[tk].insert(tpl);
}
if(tr[nw].l==tr[nw].r){
    int nwpl=tr[nw].l;
    for(int iid=0;iid<fq[nwpl].size();iid++){
        int id=fq[nwpl][iid];
        int pl=qpl[id];
        for(int k=1;k<=K;k++){
            auto it=mst[k].lower_bound(pl);
            int v=abs((*it)-pl);
            it=prev(it);
            int vv=abs((*it)-pl);
            ans[id]=max(ans[id],min(v,vv));
        }
    }
}else{
    dfs(nw*2);
    dfs(nw*2+1);
}
for(int i=0;i<tr[nw].eve.size();i++){
    int tk=tr[nw].eve[i].second;
    int tpl=tr[nw].eve[i].first;
    mst[tk].erase(mst[tk].find(tpl) );
}


}

signed main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>K>>Q;
    for(int i=1;i<=K;i++){
        mst[i].insert(-2e9);
        mst[i].insert(2e9);
    }
    for(int i=1;i<=n;i++){
        cin>>xar[i]>>typ[i]>>ta[i]>>tb[i];
    }
    for(int i=1;i<=Q;i++){
        cin>>qpl[i]>>qt[i];
    //    ansl[i]=0;ansr[i]=1e9;
    }
    lisanhua();
    buildtr(1,1,500005);
    for(int i=1;i<=n;i++){
        upd(1,ta[i],tb[i],{xar[i],typ[i]});
    }
    for(int i=1;i<=Q;i++){
        fq[qt[i]].push_back(i);
    }
    dfs(1);
    for(int i=1;i<=Q;i++){
        if(ans[i]>=1e9){
            cout<<-1<<endl;
        }else{
            cout<<ans[i]<<endl;
        }
    }

}


/*
int kcnt;
int freq[500005];
void add(int v){
freq[v]++;
if(freq[v]==1){
    kcnt++;
}
}
void del(int v){
freq[v]--;
if(freq[v]==0){
    kcnt--;
}
}
*/

Compilation message

new_home.cpp: In function 'void dfs(long long int)':
new_home.cpp:59:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 | for(int i=0;i<tr[nw].eve.size();i++){
      |             ~^~~~~~~~~~~~~~~~~~
new_home.cpp:66:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int iid=0;iid<fq[nwpl].size();iid++){
      |                   ~~~^~~~~~~~~~~~~~~~
new_home.cpp:81:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 | for(int i=0;i<tr[nw].eve.size();i++){
      |             ~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 102092 KB Output is correct
2 Correct 48 ms 102136 KB Output is correct
3 Correct 48 ms 102100 KB Output is correct
4 Correct 51 ms 102040 KB Output is correct
5 Correct 50 ms 102208 KB Output is correct
6 Correct 52 ms 102208 KB Output is correct
7 Correct 56 ms 102476 KB Output is correct
8 Correct 51 ms 102220 KB Output is correct
9 Correct 51 ms 102344 KB Output is correct
10 Correct 50 ms 102212 KB Output is correct
11 Correct 50 ms 102260 KB Output is correct
12 Correct 51 ms 102260 KB Output is correct
13 Correct 57 ms 102244 KB Output is correct
14 Correct 57 ms 102124 KB Output is correct
15 Correct 50 ms 102288 KB Output is correct
16 Correct 51 ms 102304 KB Output is correct
17 Correct 49 ms 102284 KB Output is correct
18 Correct 50 ms 102188 KB Output is correct
19 Correct 59 ms 102312 KB Output is correct
20 Correct 51 ms 102220 KB Output is correct
21 Correct 63 ms 102316 KB Output is correct
22 Correct 51 ms 102236 KB Output is correct
23 Correct 51 ms 102220 KB Output is correct
24 Correct 53 ms 102280 KB Output is correct
25 Correct 52 ms 102296 KB Output is correct
26 Correct 52 ms 102252 KB Output is correct
27 Correct 51 ms 102184 KB Output is correct
28 Correct 50 ms 102244 KB Output is correct
29 Correct 54 ms 102224 KB Output is correct
30 Correct 51 ms 102148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 102092 KB Output is correct
2 Correct 48 ms 102136 KB Output is correct
3 Correct 48 ms 102100 KB Output is correct
4 Correct 51 ms 102040 KB Output is correct
5 Correct 50 ms 102208 KB Output is correct
6 Correct 52 ms 102208 KB Output is correct
7 Correct 56 ms 102476 KB Output is correct
8 Correct 51 ms 102220 KB Output is correct
9 Correct 51 ms 102344 KB Output is correct
10 Correct 50 ms 102212 KB Output is correct
11 Correct 50 ms 102260 KB Output is correct
12 Correct 51 ms 102260 KB Output is correct
13 Correct 57 ms 102244 KB Output is correct
14 Correct 57 ms 102124 KB Output is correct
15 Correct 50 ms 102288 KB Output is correct
16 Correct 51 ms 102304 KB Output is correct
17 Correct 49 ms 102284 KB Output is correct
18 Correct 50 ms 102188 KB Output is correct
19 Correct 59 ms 102312 KB Output is correct
20 Correct 51 ms 102220 KB Output is correct
21 Correct 63 ms 102316 KB Output is correct
22 Correct 51 ms 102236 KB Output is correct
23 Correct 51 ms 102220 KB Output is correct
24 Correct 53 ms 102280 KB Output is correct
25 Correct 52 ms 102296 KB Output is correct
26 Correct 52 ms 102252 KB Output is correct
27 Correct 51 ms 102184 KB Output is correct
28 Correct 50 ms 102244 KB Output is correct
29 Correct 54 ms 102224 KB Output is correct
30 Correct 51 ms 102148 KB Output is correct
31 Correct 1894 ms 135752 KB Output is correct
32 Correct 340 ms 120932 KB Output is correct
33 Correct 496 ms 131700 KB Output is correct
34 Correct 1569 ms 131856 KB Output is correct
35 Correct 1072 ms 135840 KB Output is correct
36 Correct 585 ms 135764 KB Output is correct
37 Correct 393 ms 128376 KB Output is correct
38 Correct 383 ms 128248 KB Output is correct
39 Correct 285 ms 123984 KB Output is correct
40 Correct 301 ms 125060 KB Output is correct
41 Correct 495 ms 126680 KB Output is correct
42 Correct 568 ms 126736 KB Output is correct
43 Correct 338 ms 120392 KB Output is correct
44 Correct 447 ms 126264 KB Output is correct
45 Correct 341 ms 123700 KB Output is correct
46 Correct 252 ms 119128 KB Output is correct
47 Correct 221 ms 118472 KB Output is correct
48 Correct 220 ms 117472 KB Output is correct
49 Correct 242 ms 120396 KB Output is correct
50 Correct 391 ms 125292 KB Output is correct
51 Correct 250 ms 119296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5097 ms 155216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5051 ms 168472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 102092 KB Output is correct
2 Correct 48 ms 102136 KB Output is correct
3 Correct 48 ms 102100 KB Output is correct
4 Correct 51 ms 102040 KB Output is correct
5 Correct 50 ms 102208 KB Output is correct
6 Correct 52 ms 102208 KB Output is correct
7 Correct 56 ms 102476 KB Output is correct
8 Correct 51 ms 102220 KB Output is correct
9 Correct 51 ms 102344 KB Output is correct
10 Correct 50 ms 102212 KB Output is correct
11 Correct 50 ms 102260 KB Output is correct
12 Correct 51 ms 102260 KB Output is correct
13 Correct 57 ms 102244 KB Output is correct
14 Correct 57 ms 102124 KB Output is correct
15 Correct 50 ms 102288 KB Output is correct
16 Correct 51 ms 102304 KB Output is correct
17 Correct 49 ms 102284 KB Output is correct
18 Correct 50 ms 102188 KB Output is correct
19 Correct 59 ms 102312 KB Output is correct
20 Correct 51 ms 102220 KB Output is correct
21 Correct 63 ms 102316 KB Output is correct
22 Correct 51 ms 102236 KB Output is correct
23 Correct 51 ms 102220 KB Output is correct
24 Correct 53 ms 102280 KB Output is correct
25 Correct 52 ms 102296 KB Output is correct
26 Correct 52 ms 102252 KB Output is correct
27 Correct 51 ms 102184 KB Output is correct
28 Correct 50 ms 102244 KB Output is correct
29 Correct 54 ms 102224 KB Output is correct
30 Correct 51 ms 102148 KB Output is correct
31 Correct 1894 ms 135752 KB Output is correct
32 Correct 340 ms 120932 KB Output is correct
33 Correct 496 ms 131700 KB Output is correct
34 Correct 1569 ms 131856 KB Output is correct
35 Correct 1072 ms 135840 KB Output is correct
36 Correct 585 ms 135764 KB Output is correct
37 Correct 393 ms 128376 KB Output is correct
38 Correct 383 ms 128248 KB Output is correct
39 Correct 285 ms 123984 KB Output is correct
40 Correct 301 ms 125060 KB Output is correct
41 Correct 495 ms 126680 KB Output is correct
42 Correct 568 ms 126736 KB Output is correct
43 Correct 338 ms 120392 KB Output is correct
44 Correct 447 ms 126264 KB Output is correct
45 Correct 341 ms 123700 KB Output is correct
46 Correct 252 ms 119128 KB Output is correct
47 Correct 221 ms 118472 KB Output is correct
48 Correct 220 ms 117472 KB Output is correct
49 Correct 242 ms 120396 KB Output is correct
50 Correct 391 ms 125292 KB Output is correct
51 Correct 250 ms 119296 KB Output is correct
52 Runtime error 341 ms 281812 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 102092 KB Output is correct
2 Correct 48 ms 102136 KB Output is correct
3 Correct 48 ms 102100 KB Output is correct
4 Correct 51 ms 102040 KB Output is correct
5 Correct 50 ms 102208 KB Output is correct
6 Correct 52 ms 102208 KB Output is correct
7 Correct 56 ms 102476 KB Output is correct
8 Correct 51 ms 102220 KB Output is correct
9 Correct 51 ms 102344 KB Output is correct
10 Correct 50 ms 102212 KB Output is correct
11 Correct 50 ms 102260 KB Output is correct
12 Correct 51 ms 102260 KB Output is correct
13 Correct 57 ms 102244 KB Output is correct
14 Correct 57 ms 102124 KB Output is correct
15 Correct 50 ms 102288 KB Output is correct
16 Correct 51 ms 102304 KB Output is correct
17 Correct 49 ms 102284 KB Output is correct
18 Correct 50 ms 102188 KB Output is correct
19 Correct 59 ms 102312 KB Output is correct
20 Correct 51 ms 102220 KB Output is correct
21 Correct 63 ms 102316 KB Output is correct
22 Correct 51 ms 102236 KB Output is correct
23 Correct 51 ms 102220 KB Output is correct
24 Correct 53 ms 102280 KB Output is correct
25 Correct 52 ms 102296 KB Output is correct
26 Correct 52 ms 102252 KB Output is correct
27 Correct 51 ms 102184 KB Output is correct
28 Correct 50 ms 102244 KB Output is correct
29 Correct 54 ms 102224 KB Output is correct
30 Correct 51 ms 102148 KB Output is correct
31 Correct 1894 ms 135752 KB Output is correct
32 Correct 340 ms 120932 KB Output is correct
33 Correct 496 ms 131700 KB Output is correct
34 Correct 1569 ms 131856 KB Output is correct
35 Correct 1072 ms 135840 KB Output is correct
36 Correct 585 ms 135764 KB Output is correct
37 Correct 393 ms 128376 KB Output is correct
38 Correct 383 ms 128248 KB Output is correct
39 Correct 285 ms 123984 KB Output is correct
40 Correct 301 ms 125060 KB Output is correct
41 Correct 495 ms 126680 KB Output is correct
42 Correct 568 ms 126736 KB Output is correct
43 Correct 338 ms 120392 KB Output is correct
44 Correct 447 ms 126264 KB Output is correct
45 Correct 341 ms 123700 KB Output is correct
46 Correct 252 ms 119128 KB Output is correct
47 Correct 221 ms 118472 KB Output is correct
48 Correct 220 ms 117472 KB Output is correct
49 Correct 242 ms 120396 KB Output is correct
50 Correct 391 ms 125292 KB Output is correct
51 Correct 250 ms 119296 KB Output is correct
52 Execution timed out 5097 ms 155216 KB Time limit exceeded
53 Halted 0 ms 0 KB -