Submission #1092476

# Submission time Handle Problem Language Result Execution time Memory
1092476 2024-09-24T07:44:17 Z alexander707070 Gap (APIO16_gap) C++14
19.1947 / 100
76 ms 8896 KB
#include<bits/stdc++.h>
#include "gap.h"

#define MAXN 600007
using namespace std;

struct interval{
    long long from,to;

    inline friend bool operator < (interval fr,interval sc){
        return fr.to-fr.from<sc.to-sc.from;
    }
};

priority_queue<interval> q,qq;

pair<interval,interval> check(long long l,long long r){
    if(l+1==r)return {{-1,-1},{-1,-1}};

	long long mid=(l+r)/2;

    long long *ll,*rr,*lt,*rt;

	ll=new long long();
	rr=new long long();

	lt=new long long();
	rt=new long long();

    MinMax(l+1,mid, ll,rr);
	
	if(mid+1<=r-1)MinMax(mid+1,r-1, lt,rt);
	else{
		*lt=-1; *rt=-1;
	}

    return {{*ll,*rr},{*lt,*rt}};
}

const long long inf=1e18;

long long *l,*r;

bool better(){
	if(qq.empty())return true;
	return q.top().to-q.top().from > qq.top().to-qq.top().from;
}

long long findGap(int T, int N){

	while(!q.empty())q.pop();

	l=new long long();
	r=new long long();

    MinMax(1, inf, l,r);
    q.push({*l,*r});

    while(better()){
        pair<interval,interval> s=check(q.top().from,q.top().to);

        if(s.first.from==-1 and s.second.to==-1)return q.top().to-q.top().from;

        interval z=q.top();
        q.pop();

		if(s.second.from==-1)swap(s.first,s.second);

		if(s.first.from==-1){
			qq.push({z.from,s.second.from});
			qq.push({s.second.to,z.to});

			if(s.second.from!=s.second.to)q.push({s.second.from,s.second.to});
		}else{
			qq.push({z.from,s.first.from});
			qq.push({s.second.to,z.to});
			qq.push({s.first.to,s.second.from});

			if(s.first.from!=s.first.to)q.push({s.first.from,s.second.from});
			if(s.second.from!=s.second.to)q.push({s.second.from,s.second.to});
		}
    }

	return qq.top().to-qq.top().from;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Incorrect 0 ms 344 KB Output isn't correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Incorrect 1 ms 344 KB Output isn't correct
16 Correct 8 ms 1112 KB Output is correct
17 Correct 7 ms 856 KB Output is correct
18 Correct 6 ms 856 KB Output is correct
19 Correct 7 ms 1064 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 36 ms 2856 KB Output is correct
22 Correct 32 ms 2760 KB Output is correct
23 Correct 27 ms 2768 KB Output is correct
24 Correct 27 ms 2768 KB Output is correct
25 Incorrect 75 ms 8836 KB Output isn't correct
26 Correct 40 ms 2760 KB Output is correct
27 Correct 34 ms 2764 KB Output is correct
28 Correct 28 ms 2720 KB Output is correct
29 Correct 27 ms 2760 KB Output is correct
30 Correct 12 ms 1112 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Partially correct 0 ms 344 KB Partially correct
4 Correct 0 ms 344 KB Output is correct
5 Partially correct 0 ms 344 KB Partially correct
6 Partially correct 1 ms 344 KB Partially correct
7 Partially correct 0 ms 344 KB Partially correct
8 Partially correct 0 ms 344 KB Partially correct
9 Partially correct 0 ms 344 KB Partially correct
10 Partially correct 0 ms 344 KB Partially correct
11 Partially correct 1 ms 344 KB Partially correct
12 Partially correct 1 ms 344 KB Partially correct
13 Partially correct 1 ms 344 KB Partially correct
14 Partially correct 1 ms 344 KB Partially correct
15 Partially correct 1 ms 356 KB Partially correct
16 Partially correct 7 ms 1212 KB Partially correct
17 Partially correct 7 ms 1112 KB Partially correct
18 Partially correct 7 ms 912 KB Partially correct
19 Partially correct 7 ms 856 KB Partially correct
20 Partially correct 2 ms 600 KB Partially correct
21 Partially correct 30 ms 2832 KB Partially correct
22 Partially correct 29 ms 2764 KB Partially correct
23 Partially correct 27 ms 2760 KB Partially correct
24 Partially correct 35 ms 2768 KB Partially correct
25 Partially correct 76 ms 8896 KB Partially correct
26 Partially correct 27 ms 2760 KB Partially correct
27 Partially correct 28 ms 3004 KB Partially correct
28 Partially correct 31 ms 3024 KB Partially correct
29 Partially correct 28 ms 2928 KB Partially correct
30 Partially correct 9 ms 1112 KB Partially correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct