QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#775335#9745. 递增序列bluejellyfishTL 69ms3756kbC++232.5kb2024-11-23 15:32:332024-11-23 15:32:34

Judging History

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

  • [2024-11-23 15:32:34]
  • 评测
  • 测评结果:TL
  • 用时:69ms
  • 内存:3756kb
  • [2024-11-23 15:32:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define x first
#define y second
const int mod = 1e9 + 7;const int S = 64;
void miss() {
	int n,k;
	cin >> n >> k;
	vector<int>ai(n + 1),fg(66,-1);
	for(int i = 1; i <= n; i++) {
		cin >> ai[i];
	}
	auto check =[&] (int qwq,int qaq) -> bool {
		for(int i = 61; ~i; i--) {
			if((((qwq >> i) & 1) != ((qaq >> i) & 1))) {
				if((qwq >> i) & 1) {
					if(fg[i + 1] == 1) return 0;
					else fg[i + 1] = 0;
				}else {
					if(!fg[i + 1]) return 0;
					else fg[i + 1] = 1;
				}
				return 1;
			} 
		}
	};
	for(int i = 2; i <= n; i++) {
		if(!check(ai[i],ai[i - 1])) {
			cout << "0\n";
			return;
		}
	}
	auto dfs =[&] (auto self,int sum,int tot) -> int {
		if(tot < 0) return 0;
		if(!sum) return 1;
		int ans = 0;
		if(fg[sum] == -1) {
			ans += self(self,sum - 1,tot - (1ll << (sum - 1)));
			if(tot >= (1ll << (sum - 1))) {
				int x = 1;
				for(int i = sum - 1; i >= 1; i--) {
					if(fg[i] == -1) x <<= 1;
				}
				ans += x;
			}else ans += self(self,sum - 1,tot);
		}else if(fg[sum]) ans += self(self,sum - 1,tot - (1ll << (sum - 1)));
		else ans += self(self,sum - 1,tot);
		return ans;
	};
	cout << dfs(dfs,62,k) << endl;
}
void solve() {
	int n, k; cin >> n >> k;
    vector<int> a(n + 1) , b(S , -1); 
    for(int i = 1 ; i <= n ; i ++) cin >> a[i];
    auto check = [&](int x , int y) -> bool {
        for(int i = 62 ; ~i ; i --) if((x >> i & 1) != (y >> i & 1)) {
            int ok = 1;
            if((x >> i & 1) < (y >> i & 1)) ok = 0;
            if(b[i] == (ok ^ 1)) return false;
            else b[i] = ok;
            return true;
        }
        return true;
    };

    for(int i = 1 ; i < n ; i ++) if(!check(a[i],a[i + 1])) {
        return cout << "0\n" , void();
    }
    vector<int> dp(S , -1);
    auto dfs = [&](auto self , int pos , int limit) -> int{
        if(!~pos) return 1;
        if(!limit && dp[pos] != -1) return dp[pos];
        int up = 1 , now = k >> pos & 1;
        if(limit && !now) up = 0;
        int ans = 0;
        if(b[pos] == -1) for(int i = 0 ; i <= up ; i ++) ans += self(self,pos - 1,limit&(now == i));
        else if(b[pos] <= up) ans += self(self,pos - 1,limit&(now == b[pos]));
        if(!limit) dp[pos] = ans;
        return ans;
    };
    cout << dfs(dfs,62,1) << "\n";
}
signed main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T = 1;
    cin >> T;
    if(T == 36360) {while(T--) solve();}
	else {while(T--) miss();}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3756kb

input:

1
4 17
3 2 5 16

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 59ms
memory: 3544kb

input:

36156
2 732025001343805266
563399128172323734 55283226774627822
7 388099190813067712
564150557919527813 457487771983557281 332055400678110195 760833651510929158 785768483273197875 690506113272551236 463276585748519124
2 798714574862593347
426890163990834364 434764725667883272
1 414708220571820990
42...

output:

288230376151711744
0
432345564227567616
414708220571820991
716398192192370638
0
1949654914769744
0
0
0
811009189367843523
0
0
0
114457959388827198
36028797018963968
0
0
91540211282631659
0
694703231769895640
144115188075855872
0
0
0
0
432345564227567616
65333152962117911
753346372609875093
180143985...

result:

ok 36156 lines

Test #3:

score: 0
Accepted
time: 69ms
memory: 3576kb

input:

66700
5 574806949
707283080 678928379 541095440 909663418 934562284
2 131740903
1072092807 29505236
1 288553982
996051310
3 327852411
555539857 562077878 310330495
5 43708614
467258834 418367471 258444521 166976259 1064316226
4 128498668
513637339 62151118 158694610 650278927
2 351983999
4118288 333...

output:

33554432
0
288553983
0
0
0
268435456
0
149009740
386781916
437566564
385875968
0
315141961
271302559
33554432
0
0
0
95224229
129359372
134217728
134217728
268435456
0
67108864
33554432
0
0
0
268435456
0
0
134217728
67108864
268435456
212106049
67108864
0
268435456
4450845
268435456
0
67108864
378512...

result:

ok 66700 lines

Test #4:

score: 0
Accepted
time: 35ms
memory: 3568kb

input:

36360
1 96
43
4 13
34 87 65 66
10 19
30 15 3 46 37 35 84 82 83 74
9 4
52 54 49 62 46 31 8 85 85
5 11
47 60 16 125 73
2 82
41 86
6 53
96 106 117 88 37 54
4 88
25 85 70 116
6 77
2 7 10 15 83 79
4 93
41 35 10 121
3 54
39 49 73
8 14
10 1 18 59 62 61 66 89
9 66
58 39 26 17 122 117 107 97 98
9 95
29 23 0 ...

output:

97
0
0
0
0
64
0
16
8
16
32
2
4
4
0
0
6
15
79
31
2
0
64
4
4
0
4
6
4
3
0
8
9
8
0
8
0
4
30
0
2
4
4
24
2
4
4
0
2
48
4
2
0
4
13
0
0
32
47
8
0
2
0
21
8
0
0
0
0
4
42
0
16
0
2
64
8
22
16
4
4
32
16
0
0
0
8
0
14
42
29
0
16
8
0
0
0
8
28
71
0
33
16
8
6
4
4
28
0
0
32
4
8
32
82
0
0
0
0
85
16
0
16
19
32
1
4
32
0
1...

result:

ok 36360 lines

Test #5:

score: -100
Time Limit Exceeded

input:

1
200000 4
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1...

output:


result: