第十届山东理工大学ACM网络编程擂台赛 正式赛E

From axuhongbo, 3 Years ago, written in Plain Text, viewed 400 times.
URL http://axuhongbo.top/paste/view/7357f0da Embed
Download Paste or View Raw
  1. #include <iostream>
  2. #include <stdio.h>
  3. const int N = 1e5+100;
  4. int s[N];
  5. int main(){
  6.     int i,n,m;
  7.     scanf("%d%d",&n,&m);
  8.     for(i = 1;i <= m;i ++){
  9.         int l,r,x;
  10.         scanf("%d%d%d",&l,&r,&x);
  11.         s[l] += x;                                       //打标记  (和s[l] = s[l]+x一个意思)
  12.         s[r+1] -= x;                                   //打标记  (和s[r+1] = s[r+1]-x 一个意思)
  13.     }
  14.     for(i = 1;i <= n;i ++) s[i] += s[i-1];   //求前缀和  (和s[i] = s[i]+s[i-1]一个意思)
  15.     for(i = 1;i <= n;i ++) {
  16.         printf("%d",s[i]);
  17.         if(i != n) printf(" ");
  18.     }
  19.     return 0;
  20. }
  21.  

Reply to "第十届山东理工大学ACM网络编程擂台赛 正式赛E"

Here you can reply to the paste above

captcha