用户输出
1
2
0
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20443 | #1032. 1-03G. JM的毒瘤题 | Accepted | 100 | 506 ms | 412 K | C++ / 2.6 K | q3540555 | 2019-07-22 15:21:02 |
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define spause() system("pause")
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> prdd;
const llong inf = 0x7fffffffffffffff;
struct lar {
prdd l[2][32];
};
int q, k, l1, r1, l2, r2, ans = -1;
prdd is[2];
lar eg[2], ep[2];
bool cml(prdd itv, int lv);
int latml(prdd itv, int lv);
int getlen(prdd itv);
prdd mxlen(prdd x, prdd y);
int main() {
scanf("%d", &q);
for (int fq = 0; fq < q; fq++) {
scanf("%d", &k);
for (int i = 0; i < 2; i++) scanf("%d%d", &is[i].first, &is[i].second);
// WARNING: [a, b]
eg[0].l[0][k] = eg[0].l[1][k] = is[0];
eg[1].l[0][k] = eg[1].l[1][k] = is[1];
int a[2];
for (int i = k; i > 0; i--)
for (a[0] = 0; a[0] < 2; a[0]++)
for (a[1] = 0; a[1] < 2; a[1]++) {
// printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", i, ans, eg[0].l[a[0]][i].first,
// eg[0].l[a[0]][i].second, eg[1].l[a[1]][i].first, eg[1].l[a[1]][i].second,
// cml(eg[0].l[a[0]][i], i), cml(eg[1].l[a[1]][i], i));
if (cml(eg[0].l[a[0]][i], i) && cml(eg[1].l[a[1]][i], i))
ans = max(
ans,
min(eg[0].l[a[0]][i].second % (1 << i), eg[1].l[a[1]][i].second % (1 << i)) -
max(eg[0].l[a[0]][i].first % (1 << i), eg[1].l[a[1]][i].first % (1 << i)));
for (int tp = 0; tp < 2; tp++)
if (cml(eg[tp].l[a[tp]][i], i)) {
prdd lp = prdd(eg[tp].l[a[tp]][i].first, latml(eg[tp].l[a[tp]][i], i) - 1),
rp = prdd(latml(eg[tp].l[a[tp]][i], i) + 1, eg[tp].l[a[tp]][i].second);
eg[tp].l[0][i - 1] = mxlen(eg[tp].l[0][i - 1], lp);
eg[tp].l[1][i - 1] = mxlen(eg[tp].l[1][i - 1], rp);
} else
eg[tp].l[a[tp]][i - 1] = mxlen(eg[tp].l[a[tp]][i - 1], eg[tp].l[a[tp]][i]);
}
printf("%d\n", ans + 1);
ans = -1;
eg[0] = ep[0];
eg[1] = ep[1];
}
spause();
return 0;
}
bool cml(prdd itv, int lv) {
if (itv.first == 0)
return false;
return (itv.second >> (lv - 1) & 1) - ((itv.first - 1) >> (lv - 1) & 1);
}
int latml(prdd itv, int lv) {
if (itv.first == 0)
return 0;
return (itv.second >> (lv - 1)) << (lv - 1);
}
int getlen(prdd itv) { return itv.second - itv.first; }
prdd mxlen(prdd x, prdd y) {
if (getlen(x) > getlen(y))
return x;
else if (getlen(x) < getlen(y))
return y;
if (x.first == 0)
return y;
else
return x;
}
用户输出
1
2
0
系统信息
Exited with return code 0
18
30 3 6 1 4
30 1 1 4 4
30 2 2 6 6
30 1 1 1 1
30 1 1 2 3
30 2 3 1 1
30 4 5 6 7
30 5 6 5 10
<126 bytes omitted>
用户输出
2
0
1
1
1
1
1
2
2
3
3
3
3
4
4
1
1
8
系统信息
Exited with return code 0
45
30 73426655 594361930 343984155 989446962
30 169720415 312105195 670978284 671296539
30 20 59
<1585 bytes omitted>
379149396
207899
5
103
2901
19516
112739
4151539
7731787
530010446
1000000000
71194568
8
<301 bytes omitted>
用户输出
379149396
207899
5
103
2901
19516
112739
4151539
7731787
530010446
1000000000
71194568
8140525
28429169
268435455
463129088
4631
<228 bytes omitted>
系统信息
Exited with return code 0
100000
11 103 1997 1063 1222
26 24644974 48409450 51667909 57999424
2 3 3 3 3
26 3660266 5056371
<2667925 bytes omitted>
160
6331516
1
669897
1502512
8644289
1107
154443
2295
1
30891
15
7171342
11
2819
1215
<609656 bytes omitted>
用户输出
160
6331516
1
669897
1502512
8644289
1107
154443
2295
1
30891
15
7171342
11
2819
12156
733
194
29096358
151
5916
1
92366
174
321
<509628 bytes omitted>
系统信息
Exited with return code 0
100000
30 642049148 976948557 570976641 972271279
30 562317312 772318035 72539938 682025304
30 30
<4380333 bytes omitted>
330222132
210000724
120072017
43243530
87344032
51372755
134353734
306730318
235458160
6499
<1031634 bytes omitted>
用户输出
330222132
210000724
120072017
43243530
87344032
51372755
134353734
306730318
235458160
6499998
134574977
4027250
218285468
83887
<931606 bytes omitted>
系统信息
Exited with return code 0