2017 ZSTU寒假排位赛 #5

  题目链接:https://vjudge.net/contest/148901#overview

  A题,排序以后xjbg即可。

  B题,弄个数组记录当前列是不是删除以及当前行是不是已经大于下一行然后乱搞即可。

  C题,线段树写的比较无脑,但是可以直接搞,在遍历的时候记录最大的,然后继续找的时候更新答案即可。

  D题,题意是给出m个限制条件,每个限制条件表示[L,R]范围内&和为x。问是不是存在这样的数组。方法是线段树记录区间内&的和。然后m组每次更新[L,R]都使得|上x,因为要&为1,二进制下该位必须为1,而|上去能够使得这位结果必为1(很巧妙)。然后就可以做了。代码如下:

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 #include <map>
 5 #include <vector>
 6 #include <queue>
 7 #include <set>
 8 #include <iostream>
 9 #define t_mid (l+r>>1)
10 #define ls (o<<1)
11 #define rs (o<<1|1)
12 #define lson ls,l,t_mid
13 #define rson rs,t_mid+1,r
14 using namespace std;
15 const int N = 100000 + 5;
16 typedef long long ll;
17 typedef pair<int,int> pii;
18 
19 int c[N<<2];
20 int lazy[N<<2];
21 int n,m;
22 void up(int o) {c[o] = c[ls] & c[rs];}
23 void down(int o,int l,int r)
24 {
25     if(l == r) return ;
26     if(lazy[o])
27     {
28         c[ls] |= lazy[o];
29         c[rs] |= lazy[o];
30         lazy[ls] |= lazy[o];
31         lazy[rs] |= lazy[o];
32         lazy[o] = 0;
33     }
34 }
35 void build(int o,int l,int r)
36 {
37     if(l == r)
38     {
39         c[o] = lazy[o] = 0;
40         return ;
41     }
42     build(lson);
43     build(rson);
44     up(o);
45 }
46 void update(int o,int l,int r,int ql,int qr,int f)
47 {
48     if(l == ql && r == qr)
49     {
50         c[o] |= f;
51         lazy[o] |= f;
52         return ;
53     }
54     down(o,l,r);
55     if(qr <= t_mid) update(lson,ql,qr,f);
56     else if(ql > t_mid) update(rson,ql,qr,f);
57     else
58     {
59         update(lson,ql,t_mid,f);
60         update(rson,t_mid+1,qr,f);
61     }
62     up(o);
63 }
64 int query(int o,int l,int r,int ql,int qr)
65 {
66     if(l == ql && r == qr) return c[o];
67     down(o,l,r);
68     if(qr <= t_mid) return query(lson,ql,qr);
69     else if(ql > t_mid) return query(rson,ql,qr);
70     else return query(lson,ql,t_mid) & query(rson,t_mid+1,qr);
71 }
72 
73 int x[N],y[N],z[N];
74 bool can()
75 {
76     for(int i=1;i<=m;i++)
77     {
78         if(query(1,1,n,x[i],y[i]) != z[i]) return false;
79     }
80 
81     puts("YES");
82     for(int i=1;i<=n;i++) printf("%d%c",query(1,1,n,i,i), i==n?'\n':' ');
83     return true;
84 }
85 
86 int main()
87 {
88     cin >> n >> m;
89     for(int i=1;i<=m;i++)
90     {
91         scanf("%d%d%d",x+i,y+i,z+i);
92         update(1,1,n,x[i],y[i],z[i]);
93     }
94     if(can() == false) puts("NO");
95     return 0;
96 }
D

 

  E题,思路参见这个。我自己代码如下:

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 #include <map>
 5 #include <vector>
 6 #include <queue>
 7 #include <set>
 8 #include <iostream>
 9 #define t_mid (l+r>>1)
10 #define ls (o<<1)
11 #define rs (o<<1|1)
12 #define lson ls,l,t_mid
13 #define rson rs,t_mid+1,r
14 using namespace std;
15 const int N = 100000 + 5;
16 typedef long long ll;
17 typedef pair<int,int> pii;
18 
19 ll a[100];
20 ll p,q;
21 int n;
22 
23 int main()
24 {
25     cin >> p >> q;
26     cin >> n;
27     for(int i=1;i<=n;i++) cin >> a[i];
28     int i;
29     for(i=1;i<=n;i++)
30     {
31         if(q == 0 || (double)p/q < a[i]) break;
32         p -= a[i] * q;
33         swap(p, q);
34     }
35     if(i == n + 1 && q == 0) puts("YES");
36     else puts("NO");
37     return 0;
38 }
E

 

转载于:https://www.cnblogs.com/zzyDS/p/6351726.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值