zoukankan      html  css  js  c++  java
  • CF 248B 前缀和

    操作1 l r 是原序列l-r的和
    操作2 l r 是从小到大排序后的l-r的和


    input
    6
    6 4 2 7 2 7
    3
    2 3 6
    1 3 4
    1 1 6
    output
    24
    9
    28

     1 # include <iostream>
     2 # include <cstdio>
     3 # include <cstring>
     4 # include <algorithm>
     5 # include <string>
     6 # include <cmath>
     7 # include <queue>
     8 # include <list>
     9 # define LL long long
    10 using namespace std ;
    11 
    12 LL a[100010] ;
    13 LL b[100010] ;
    14 
    15 LL a_sum[100010] ;
    16 LL b_sum[100010] ;
    17 
    18 int main()
    19 {
    20     //freopen("in.txt","r",stdin) ;
    21     int n , m ;
    22     while(scanf("%d" , &n) != EOF)
    23     {
    24         int i ;
    25         for (i = 0 ; i < n ; i++)
    26         {
    27             scanf("%I64d" , &a[i]) ;
    28             b[i] = a[i] ;
    29         }
    30         sort(b , b+n) ;
    31         a_sum[0] = b_sum[0] ;
    32         for (i = 1 ; i <= n ; i++)
    33         {
    34             a_sum[i] = a_sum[i-1] + a[i-1] ;
    35             b_sum[i] = b_sum[i-1] + b[i-1] ;
    36         }
    37         scanf("%d" , &m) ;
    38         while(m--)
    39         {
    40             int op , l , r ;
    41             scanf("%d%d%d" , &op , &l , &r) ;
    42             if (op == 1)
    43                 printf("%I64d
    " , a_sum[r]-a_sum[l-1]) ;
    44             else
    45                 printf("%I64d
    " , b_sum[r]-b_sum[l-1]) ;
    46         }
    47     }
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    多线程 -- H2O 生成、交替打印字符串
    打印零与奇偶数
    h2数据库的使用
    rtx应用和开发
    MongoDB--副本集
    Python 推导式
    Bootstrap组件
    Python logging日志的自动分割
    python watchdog监控文件修改
    Linux流量监控iftop
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4855183.html
Copyright © 2011-2022 走看看