[关闭]
@2368860385 2018-07-06T02:22:35.000000Z 字数 1893 阅读 216

1004——Codeforces Round #495 (Div. 2)

http://codeforces.com/contest/1004

codeforces

2018.7.6(凌晨)参加,(ABC)
2018.7.6整理


A:
模拟

B:
推一下结论发现,直接输出0101010...

C:
线段树,枚举左端点,查询右边有多少不同的数,权值线段树。没开longlnog第一次Wa了。。。

upd:想复杂了,不需要线段树。首先就来一个变量表示有多少个不同的数num,记录每个点出现了多少次cnt[]。然后从左边开始往右扫,扫过一个点,cnt[a[i]]--,如果cnt[a[i]]==0了,说明这是最后一个a[i],往右就没有了,于是num--,然后ans+=num。

E:
思路:二分,然后判断。反正代码写的有问题。
正解:k个点一定在直径上,然后类似滑动窗口的,每次选k个点,更新答案。

A:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline LL read() {
  5. LL x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. const int D = 1e9;
  9. map<LL,int> p;
  10. LL a[110];
  11. int main () {
  12. LL n = read(),d = read(),ans = 0;
  13. for (int i=1; i<=n; ++i) {
  14. a[i] = read();
  15. }
  16. ans += 2;
  17. for (int i=1; i<n; ++i) {
  18. LL t1 = a[i] + d;
  19. LL t2 = a[i+1] - d;
  20. if (t1 == t2) ans++;
  21. else if (t1 < t2){
  22. ans += 2;
  23. }
  24. }
  25. cout << ans;
  26. return 0;
  27. }

B:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. int main () {
  9. int n = read(),m = read();
  10. for (int i=1; i<=n; ++i) {
  11. if (i & 1) cout << 0;
  12. else cout << 1;
  13. }
  14. return 0;
  15. }

C:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. const int N = 500010;
  9. int sum[N],a[N],c[N];
  10. bool f[N];
  11. #define Root 1,mx,1
  12. #define lson l,mid,rt<<1
  13. #define rson mid+1,r,rt<<1|1
  14. void pushup(int rt) {
  15. sum[rt] = sum[rt<<1] + sum[rt<<1|1];
  16. }
  17. void update(int l,int r,int rt,int p,int val) {
  18. if (l == r) {sum[rt] = val;return; }
  19. int mid = (l + r) >> 1;
  20. if (p <= mid) update(lson,p,val);
  21. else update(rson,p,val);
  22. pushup(rt);
  23. }
  24. int main () {
  25. int n = read(),mx = 0;
  26. for (int i=1; i<=n; ++i)
  27. a[i] = read(),mx = max(mx,a[i]);
  28. for (int i=1; i<=n; ++i) {
  29. if (!c[a[i]]) update(Root,a[i],1);
  30. c[a[i]]++;
  31. }
  32. LL ans = 0;
  33. for (int i=1; i<=n; ++i) {
  34. c[a[i]] --;
  35. if (c[a[i]] == 0) update(Root,a[i],0);
  36. if (f[a[i]]) continue;
  37. ans += sum[1];
  38. f[a[i]] = true;
  39. }
  40. cout << ans;
  41. return 0;
  42. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注