QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21802#2832. Graph TheoryCCPSDCGK#WA 26ms5568kbC++202.4kb2022-03-08 15:54:482022-05-08 04:05:35

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 04:05:35]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:5568kb
  • [2022-03-08 15:54:48]
  • 提交

answer

#include<map>
#include<set>
#include<queue>
#include<deque>
#include<cmath>
#include<ctime>
#include<bitset>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
#define mkp make_pair
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define fs fflush(stdout)
#define ump unordered_map
#define pq priority_queue
#define clz __builtin_clz
#define ctz __builtin_ctz
#define space putchar(' ')
#define enter putchar('\n')
#define sz(x) (int)x.size()
#define np next_permutation
#define clzl __builtin_clzll
#define par __builtin_parity
#define ctzl __builtin_ctzll
#define ppc __builtin_popcount
#define parl __builtin_parityll
#define all(x) x.begin(),x.end()
#define ppcl __builtin_popcountll
#define ms(x,y) memset(x,y,sizeof(x))
#define debug(x) cerr<<#x<<"= "<<(x)<<'\n'
template<class T> inline T &read(T &x){
	x=0;int f=1;char ch=getchar();
	while(ch<48||ch>57){if(ch=='-') f=-f;ch=getchar();}
	while(ch>=48&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*=f;
}
template<class T> inline void print(T x){
	static char buf[40];static int cnt=0;
	if(x<0) putchar(45),x=-x;
	do buf[++cnt]=x%10^48;while(x/=10);
	do putchar(buf[cnt--]);while(cnt);
}
#define mod 998244353
#define inf 0x3f3f3f3f
#define fpi freopen("","r",stdin)
#define fpo freopen("","w",stdout)
pair<int,int> p[200005];
int sum[200005];
inline void add(int l,int r){if(l>r) sum[1]++;sum[l]++,sum[r]--;}
bool check(int x,int n){
	int i;
	for(i=1;i<=n;i++){
		if(p[i].second-p[i].first>x) add(p[i].second,p[i].first);
		if(n+p[i].first-p[i].second>x) add(p[i].first,p[i].second);
	}
	for(i=2;i<=n;i++) sum[i]+=sum[i-1];
	for(i=1;i<=n;i++) if(!sum[i]) return 1;return 0;
}
void solve(int n,int m){
	int l=0,r=n,ans,i;
	for(i=1;i<=n;i++) sum[i]=0; 
	for(i=1;i<=m;i++){
		read(p[i].first),read(p[i].second);
		if(p[i].first>p[i].second) p[i].first^=p[i].second^=p[i].first^=p[i].second;
		l=max(l,min(p[i].second-p[i].first,n+p[i].first-p[i].second));
	}
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid,n)) ans=mid,r=mid-1;else l=mid+1;
	}print(ans),enter;
}
int main(){
	int n,m;
	while(cin>>n>>m) solve(n,m);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3548kb

input:

3 2
1 2
2 3
3 2
1 1
2 2
3 3
1 2
2 3
3 1

output:

1
0
2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 26ms
memory: 5568kb

input:

17 17
6 10
1 9
14 6
12 13
5 4
15 17
14 15
6 5
10 6
10 11
2 9
9 6
17 15
9 15
4 8
1 4
13 15
13 19
11 10
12 10
10 5
2 8
12 11
8 3
1 7
10 9
8 5
1 5
9 4
8 7
12 10
6 8
13 1
5 8
11 5
10 8
7 7
16 14
9 5
8 1
4 16
10 8
16 15
15 1
13 5
9 3
4 4
9 7
7 2
5 4
5 11
9 14
5 13
1 5
4 5
4 1
4 4
1 1
5 3
3 5
4 1
3 2
5 1
...

output:

12
9
12
2
2
2
10
9
2
9
2
13
12
15
13
15
3
12
12
11
14
15
7
13
9
12
-1420158144
2
2
9
9
7
11
4
2
14
6
1
14
9
14
2
9
6
1
3
1
4
9
12
12
9
4
8
11
9
4
12
1
6
3
2
1
8
12
5
11
7
9
10
15
14
5
2
7
10
6
10
9
10
6
1
6
3
4
1
14
11
5
14
7
9
10
7
12
7
1
8
12
8
9
6
8
5
6
8
10
9
13
3
11
4
5
12
15
11
1
3
2
7
7
11
12...

result:

wrong answer 1st lines differ - expected: '8', found: '12'