本文主要是介绍hdu4267区间统计,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:给一些数,有两种操作,一种是在[a,b] 区间内,对(i - a)% k == 0 的加value,另一种操作是询问某个位置的值。
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.NavigableSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;public class Main {public static void main(String[] args) throws IOException{StreamTokenizer cin = new StreamTokenizer(new BufferedInputStream(System.in)); InputReader in = new InputReader(System.in) ;PrintWriter out = new PrintWriter(System.out) ;while(cin.nextToken() != cin.TT_EOF){new Task().solve(cin, out); }out.flush() ; }}class BIT{int n ;int[] cnt ;BIT(int n){this.n = n ; cnt = new int[n+1] ;}int lowbit(int x){return x & (-x) ;}void add(int i , int val){for( ; i <= n ; i += lowbit(i)) cnt[i] += val ;}int sum(int i){int s = 0 ;for( ; i > 0 ; i -= lowbit(i)) s += cnt[i] ;return s ;}
}class Task{static int N = 50008 ;static int[] num = new int[N] ;public void solve(StreamTokenizer cin , PrintWriter out) throws IOException{int n = (int)cin.nval;for(int i = 1 ; i <= n ; i++){cin.nextToken() ; num[i] = (int)cin.nval ;}BIT[][] bit = new BIT[11][10] ;for(int k = 1 ; k <= 10 ; k++){for(int j = 0 ; j < k ; j++) bit[k][j] = new BIT(n) ;}cin.nextToken() ; int q = (int)cin.nval ;while(q-- > 0){cin.nextToken() ; int kind = (int)cin.nval ;if(kind == 1){cin.nextToken() ; int a = (int)cin.nval ;cin.nextToken() ; int b = (int)cin.nval ;cin.nextToken() ; int k = (int)cin.nval ;cin.nextToken() ; int c = (int)cin.nval ;bit[k][a%k].add(a , c) ;bit[k][a%k].add(b+1, -c) ;}else{cin.nextToken() ; int i = (int)cin.nval ; int s = num[i] ;for(int k = 1 ; k <= 10 ; k++)s += bit[k][i%k].sum(i) ;out.println(s);}}}}class InputReader{public BufferedReader reader;public StringTokenizer tokenizer;public InputReader(InputStream stream){reader = new BufferedReader(new InputStreamReader(stream), 32768) ;tokenizer = null ;}public String next(){while(tokenizer == null || ! tokenizer.hasMoreTokens()){try{tokenizer = new StringTokenizer(reader.readLine());}catch (IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken(); }public int nextInt(){return Integer.parseInt(next());}public long nextLong(){return Long.parseLong(next());}public double nextDouble(){return Double.parseDouble(next());}}
这篇关于hdu4267区间统计的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!