UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213107#2348. Lifewucy1008919ms81952kbC++1.2kb2024-11-09 20:09:312024-11-09 23:12:02

answer

#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int l,q;
map <int,int> f;
int fun(int x) {
	int ls = -l,rs = l;
	while(ls <= rs) {
		int mid = (ls + rs) / 2;
		int now = mid * mid * mid;
		if(now < x) ls = mid + 1;
		else if(now == x) return mid;
		else rs = mid - 1;
	}
	return 0;
}
struct num{
	int a;
	int nm; 
}s[2001001];
int cnt;
bool cmp(num a,num b) {return a.nm < b.nm;}
int main() {
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	cin >> l >> q;
	for(int a = 0;a <= l;a ++) {
		for(int b = -l;b <= l;b ++) {
			int x = a * a * a + b * b * b;
			if(!f[x]){
				f[x] = 1;
				cnt ++;
				s[cnt].a = a;
				s[cnt].nm = x;	
			}
		} 
	}
	sort(s + 1,s + cnt + 1,cmp);
	while(q --){
		int x;
		cin >> x;
		int ls = 1;
		for(int c = l; c >= -l;c --){
			int now = x - c * c * c;
			int rs = cnt;
			while(ls <= rs) {
				int mid = (ls + rs) >> 1;
				if(s[mid].nm >= now) rs = mid - 1;
				else ls = mid + 1;
			}
			if(s[ls].nm == now) {
				cout << s[ls].a << " " << fun(s[ls].nm - s[ls].a * s[ls].a * s[ls].a) << " " << c << endl;
				ls = 1145141;
				break;
			}
		}
		if(ls != 1145141) cout << l + 1 << " " << l + 1 << " " << l + 1 << endl;
	}
}  

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 6ms
memory: 2028kb

input:

98 10
5487
1899
3043
5373
2368
3993
723
9567
6812
901

output:

14 -1 14
44 -77 72
34 -30 -21
45 -72 66
0 -12 16
44 -55 44
58 -77 64
12 -28 31
27 -66 65
14 -11 -8

result:

ok Correct!


Test #2:

score: 10
Accepted
time: 3ms
memory: 2040kb

input:

99 10
6139
3749
7532
3544
3976
345
522
8442
6400
7965

output:

100 100 100
100 100 100
14 -5 17
8 -7 15
42 -58 50
1 1 7
5 -11 12
8 -11 21
28 -24 -12
2 -51 52

result:

ok Correct!


Test #3:

score: 10
Accepted
time: 5ms
memory: 2024kb

input:

98 10
5078
9597
9394
9368
8777
6955
8020
5115
398
3771

output:

99 99 99
99 99 99
2 5 21
44 -42 -12
16 -39 40
26 -60 59
21 -9 -8
10 -14 19
15 -32 31
14 -18 19

result:

ok Correct!


Test #4:

score: 10
Accepted
time: 54ms
memory: 1920kb

input:

91 10000
163
6364
2583
7101
5320
483
6442
1028
1209
1710
5617
296
7228
1593
4580
5559
9699
2015
6397...

output:

30 -26 -21
0 -21 25
9 -7 13
30 -27 -6
36 -84 82
14 -13 -4
92 92 92
37 -60 55
7 -11 13
57 -52 -35
1 -...

result:

ok Correct!


Test #5:

score: 10
Accepted
time: 66ms
memory: 1920kb

input:

91 10000
6480
8776
1711
1745
4845
3338
343
3167
8450
2756
2252
4375
4912
9822
8053
1533
1216
4161
61...

output:

26 -44 42
61 -77 62
22 -33 30
21 -27 23
13 -20 22
13 -19 20
7 -91 91
2 -6 15
22 -13 -1
6 7 13
92 92 ...

result:

ok Correct!


Test #6:

score: 10
Accepted
time: 68ms
memory: 1980kb

input:

95 10000
91
6885
8279
384
5310
2877
4483
2176
267
393
5446
7415
3853
4223
8480
3368
6752
9898
5779
7...

output:

0 -5 6
68 -86 69
7 -4 20
8 -4 -4
12 -11 17
2 5 14
8 -5 16
2 -18 20
11 -10 -4
96 96 96
3 -42 43
4 -49...

result:

ok Correct!


Test #7:

score: 10
Accepted
time: 1918ms
memory: 74968kb

input:

952 10000
2160
9764
2079
4616
9459
4653
4400
6373
2089
7189
4202
4497
6684
119
1191
2206
9287
5365
1...

output:

80 -102 82
347 -666 633
462 -625 526
107 -136 109
11 -24 28
21 -16 -8
24 -30 26
253 -234 -150
186 -4...

result:

ok Correct!


Test #8:

score: 10
Accepted
time: 2293ms
memory: 81296kb

input:

992 10000
2576
3876
8352
3311
9101
5255
5420
145
7396
6040
8529
9794
5164
4302
7147
3683
152
1136
79...

output:

226 -302 252
119 -190 173
243 -572 557
86 -126 111
144 -380 373
126 -816 815
1 -42 43
10 -8 -7
5 -9 ...

result:

ok Correct!


Test #9:

score: 10
Accepted
time: 2093ms
memory: 81952kb

input:

996 10000
2189
8757
4831
6765
991
2216
9313
7968
7020
9945
988
9422
7315
2132
2333
5962
1798
8184
22...

output:

0 -2 13
70 -99 86
32 -97 96
23 -31 29
671 -872 712
160 -417 409
242 -447 422
7 -20 25
79 -403 402
16...

result:

ok Correct!


Test #10:

score: 10
Accepted
time: 2413ms
memory: 80652kb

input:

988 10000
1785
1065
1261
3054
2475
693
9109
9404
1153
4364
1847
8539
4364
9471
6183
6855
303
306
635...

output:

28 -23 -20
121 -200 184
80 -104 85
274 -833 823
122 -197 180
397 -742 702
154 -292 277
16 -19 23
48 ...

result:

ok Correct!


Extra Test:

score: 0
Extra Test Passed