QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#37199#1279. Distinct NumberwyhaoWA 2ms1784kbC++1.3kb2022-06-30 14:01:592022-06-30 14:02:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-30 14:02:00]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:1784kb
  • [2022-06-30 14:01:59]
  • 提交

answer

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=20005;
int TT,n,t,s;
bool vis[65];
struct node{
	int opt;
	ll x;
}A[N];int cnt;
bool cmp(node a,node b){
	return a.x<b.x;
}
int main(){
	ll x,y,l,r;
	ll a,b;
	scanf("%d",&TT);
	while(TT--){
		scanf("%d",&n);
		scanf("%lld",&x);
		y=x;t=0;s=0;cnt=0;
		while(y){
			vis[t]=y&1;
			if(y&1) s++;
			y>>=1;t++;
		}
		y=(1<<s)-1;
		for(int i=1;i<=n;i++){
			scanf("%lld%lld",&l,&r);
			if(r-l+1>x){
				A[++cnt].opt=1;
				A[cnt].x=0;
				A[++cnt].opt=2;
				A[cnt].x=y+1;
				continue;
			}
			a=b=0;
			for(int i=t;~i;i--){
				if(vis[i]){
					a<<=1;
					if((l>>i)&1) a++;
					b<<=1;
					if((r>>i)&1) b++;
				}
			}
			if(a<=b){
				A[++cnt].opt=1;
				A[cnt].x=a;
				A[++cnt].opt=2;
				A[cnt].x=b+1;
			}else{
				A[++cnt].opt=1;
				A[cnt].x=b;
				A[++cnt].opt=2;
				A[cnt].x=y+1;
				A[++cnt].opt=1;
				A[cnt].x=0;
				A[++cnt].opt=2;
				A[cnt].x=a+1;
			}
		}
		sort(A+1,A+cnt+1,cmp);
		ll ans=0,last=-1;int S=0;
		for(int i=1;i<=cnt;i++){
//			printf("---%d %lld\n",A[i].opt,A[i].x);
			if(S) ans+=A[i].x-last;
			last=A[i].x;
			while(i<cnt and A[i+1].x==A[i].x){
				if(A[i].opt==1) S++;
				else S--;
				i++;
			}
			if(A[i].opt==1) S++;
			else S--;
		}
		printf("%lld\n",ans);
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 1784kb

input:

3
2 1
1 2
343 34345
1 3
1 3
1 123242343
1 1000000000000000000

output:

2
3
32768

result:

ok 3 tokens

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 1748kb

input:

902
5 35
2 17
19 24
32 55
59 63
73 97
5 55
3 17
35 37
38 39
43 82
87 88
1 37
46 88
4 79
1 9
40 56
56 56
57 78
8 61
5 7
19 21
27 33
34 36
36 38
59 73
77 79
94 97
2 86
0 23
72 78
7 43
5 10
12 21
22 34
36 58
65 71
72 88
91 99
9 74
16 24
31 41
44 48
48 49
51 51
57 57
61 65
69 71
85 93
4 85
5 44
46 47
54...

output:

8
32
8
30
24
12
25
8
16
14
4
16
4
17
3
4
13
19
7
11
2
1
2
10
13
2
4
8
1
6
8
4
8
1
16
20
4
17
11
16
8
16
8
8
11
22
2
32
22
3
9
10
4
17
13
8
8
12
10
11
6
32
28
2
2
49
48
26
8
4
2
9
4
11
11
16
9
16
40
16
16
4
16
4
21
6
23
2
32
5
1
8
23
6
7
13
7
3
2
16
10
4
3
2
21
30
34
47
15
8
8
11
16
12
23
3
10
16
16
...

result:

wrong answer 2nd words differ - expected: '25', found: '32'