# 圈钱学堂7日游 - Day1 上午

Day1授课老师是北京大学张浩威（张过亿），上午的题水得不行...然后下午就...QAQ

Time Limit:1000ms   Memory Limit:128MB

p<=10^18，T<=100。

AC代码：

 1 #include<cstdio>
2 #include<algorithm>
3 #include<cstring>
4 #include<cmath>
5
6 inline void read(int &x)
7 {
8     char ch = getchar(),c = ch;x = 0;
9     while(ch < '0' || ch > '9') c = ch,ch = getchar();
10     while(ch <= '9' && ch >= '0') x = (x<<1)+(x<<3)+ch-'0',ch = getchar();
11     if(c == '-') x = -x;
12 }
13
14 inline void read(long long &x)
15 {
16     char ch = getchar(),c = ch;x = 0;
17     while(ch < '0' || ch > '9') c = ch,ch = getchar();
18     while(ch <= '9' && ch >= '0') x = (x<<1)+(x<<3)+ch-'0',ch = getchar();
19     if(c == '-') x = -x;
20 }
21
22 int t,flag;
23 long long l,r,mid,tmp,p;
24
25 int main()
26 {
27     freopen("cubic.in","r",stdin);
28     freopen("cubic.out","w",stdout);
30     while(t --)
31     {
33         flag = false;
34         l = 0,r = 1000001;
35         while(l <= r)
36         {
37             mid = (l+r)>>1;
38             tmp = mid*mid*mid;
39 //            printf("%I64d %I64d\n",mid,tmp);
40             if(tmp == p) {
41                 flag = true;
42                 break;
43             }
44             else if(tmp < p) l = mid+1;
45             else if(tmp > p) r = mid-1;
46         }
47         if(flag) printf("YES\n");
48         else printf("NO\n");
49     }
50     return 0;
51 }

Time Limit:1000ms   Memory Limit:128MB

p<=10^12，T<=100。

AC代码：

 1 #include<cstdio>
2 #include<algorithm>
3 #include<cstring>
4 #include<cmath>
5
6 inline void read(int &x)
7 {
8     char ch = getchar(),c = ch;x = 0;
9     while(ch < '0' || ch > '9') c = ch,ch = getchar();
10     while(ch <= '9' && ch >= '0') x = (x<<1)+(x<<3)+ch-'0',ch = getchar();
11     if(c == '-') x = -x;
12 }
13
14 inline void read(long long &x)
15 {
16     char ch = getchar(),c = ch;x = 0;
17     while(ch < '0' || ch > '9') c = ch,ch = getchar();
18     while(ch <= '9' && ch >= '0') x = (x<<1)+(x<<3)+ch-'0',ch = getchar();
19     if(c == '-') x = -x;
20 }
21
22 int t,flag;
23 long long l,r,mid,tmp,p;
24
25 int main()
26 {
27     freopen("cubicp.in","r",stdin);
28     freopen("cubicp.out","w",stdout);
30     while(t --)
31     {
33         flag = false;
34         l = 0,r = 1000001;
35         while(l <= r)
36         {
37             mid = (l+r)>>1;
38             tmp = 3*mid*(mid-1)+1;
39 //            printf("%I64d %I64d\n",mid,tmp);
40             if(tmp == p){
41                 flag = true;
42                 break;
43             }
44             else if(tmp < p) l = mid+1;
45             else if(tmp > p) r = mid-1;
46         }
47         if(flag) printf("YES\n");
48         else printf("NO\n");
49     }
50     return 0;
51 }

Time Limit:1000ms   Memory Limit:128MB

1<=n,T<=1000000,1<=li<=ri<=n,1<=xi<=n（不保证一开始的所有数都是1~n的）。

//%%%rqy太强了！运行时间碾压标程！（最后一个测试点 标程：1322ms  我修改后的标程：736ms  RQY:348ms）

AC代码：

 1 #include<cstdio>
2 #include<algorithm>
3 #include<cmath>
4 #include<cstring>
5 #include<queue>
6 #include<stack>
7
8 const int MAXN = 1000002;
9
10 int n,t,l,r,mid,lmin,lmax,rmin,rmax,ans,cnt;
11 int lf[MAXN],rt[MAXN],x[MAXN],fa[MAXN];
12
13 struct QUES
14 {
15     int l,r,x,ord;
16 }q[MAXN];
17
18 int cmp(QUES a,QUES b)
19 {return a.x > b.x;}
20
21 inline int Min(int a,int b)
22 {return a<b?a:b;}
23
24 inline int Max(int a,int b)
25 {return a>b?a:b;}
26
27 inline int find(int x)
28 {return fa[x]==x?x:fa[x]=find(fa[x]);}
29
30 bool check(int now)
31 {
32     register int i,j;cnt = 0;
33     for(i=1;i<=n+1;++i) fa[i]=i;
34     for(i = 1;i <= n;++ i)
35     {
36         if(q[i].ord > now) continue;
37         if(cnt == now) break;
38         lf[++cnt] = q[i].l,rt[cnt] = q[i].r,x[cnt] = q[i].x;
39     }
40
41     lmin = lmax = lf[1];
42     rmin = rmax = rt[1];
43     for(i = 2;i <= now;++ i)
44     {
45         if(x[i] < x[i-1])
46         {
47             if(find(lmax) > rmin) return true;
48             for(j = find(lmin);j <= rmax;++ j)
49                 fa[find(j)] = find(rmax+1);
50             lmin = lmax = lf[i];
51             rmin = rmax = rt[i];
52         }
53         else
54         {
55             lmin = Min(lmin,lf[i]);
56             lmax = Max(lmax,lf[i]);
57             rmin = Min(rmin,rt[i]);
58             rmax = Max(rmax,rt[i]);
59         }
60     }
61     if(find(lmax) > rmin) return true;
62     return false;
63 }
64
65 int main()
66 {
67     scanf("%d%d",&n,&t);
68     for(int i = 1;i <= t;++ i)
69     {
70         scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].x);
71         q[i].ord = i;
72     }
73     ans = t+1;
74     l = 1,r = t;
75     std::sort(q+1,q+1+n,cmp);
76     while(l <= r)
77     {
78         mid = (l+r)>>1;
79         if(check(mid)) r = mid-1,ans = mid;
80         else l = mid+1;
81     }
82     printf("%d\n",ans);
83     return 0;
84 }

QAQ好气哦。

T3写了暴力和各种特判（然而并没有任何卵用）。出题人不能这样QAQ

posted @ 2017-11-05 14:21 超时空灰狼菌 阅读(...) 评论(...) 编辑 收藏