[关闭]
@2368860385 2018-07-05T06:13:43.000000Z 字数 1047 阅读 214

1000——Educational Codeforces Round 46 (Rated for Div. 2)

codeforces

2018.6.18 参加(A,B,C比赛结束后2分钟A的)
2018.6.19 整理

http://codeforces.com/contest/1000


A:
模拟

B:
放的点一定是 原来点的左边或者右边,枚举。

C:
差分,判断。

D:


代码:

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 = 500100;
  9. struct Node{
  10. LL x,val;
  11. bool operator < (const Node &A) const {
  12. return x == A.x ? val > A.val : x < A.x;
  13. }
  14. }A[N];
  15. LL cnt[N];
  16. int main () {
  17. int n = read();
  18. int p = 0;
  19. for (int i=1; i<=n; ++i) {
  20. LL l,r;
  21. scanf("%I64d%I64d",&l,&r);
  22. A[++p].x = l,A[p].val = 1;
  23. A[++p].x = r,A[p].val = -1;
  24. }
  25. sort(A+1,A+p+1);
  26. int tot = 1,c = 0;
  27. for (int i=2; i<=p; ++i) {
  28. if (A[i].x == A[tot].x && A[i].val == A[tot].val) c++;
  29. else {
  30. if (A[tot].val == -1) A[tot].val -= c;
  31. else A[tot].val += c;
  32. c = 0,A[++tot] = A[i];
  33. }
  34. }
  35. if (A[tot].val == -1) A[tot].val -= c;
  36. else A[tot].val += c;
  37. int now = A[1].val;
  38. for (int i=2; i<=tot; ++i) {
  39. if (A[i-1].val > 0) cnt[now] += A[i].x-A[i-1].x;
  40. else cnt[now] += A[i].x-A[i-1].x-1;
  41. if (A[i].val < 0) cnt[now]++;
  42. now += A[i].val;
  43. }
  44. for (int i=1; i<=n; ++i) {
  45. printf("%I64d ",cnt[i]);
  46. }
  47. return 0;
  48. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注