Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.PriorityQueue;
- import java.util.Scanner;
- public class Main {
- static Scanner s = new Scanner(System.in);
- static int next2(int n){
- int k = 0;
- while (n > 1){
- if (n % 2 == 1) n++;
- k++;
- n /= 2;
- }
- return k;
- }
- static int spow(int k){
- int sum = 1;
- for (int i = 0; i < k; i++) {
- sum *= 2;
- }
- return sum;
- }
- public static void main(String[] args) {
- int t = s.nextInt();
- for (int ngnnnjg = 0; ngnnnjg < t; ngnnnjg++) {
- int n = s.nextInt();
- int q = s.nextInt();
- int real = spow(next2(n));
- int [] aa = new int [real+1];
- int [] tree = new int [2*real+1];
- for (int jfr = 0; jfr < q; jfr++) {
- int qu = s.nextInt();
- if (qu == 1){
- int index = s.nextInt();
- int k = s.nextInt();
- index = index+real;
- int razn = k-tree[index];
- while (index > 0){
- tree[index] += razn;
- index /= 2;
- }
- }
- else{
- int l = s.nextInt();
- int r = s.nextInt();
- int sum = 0;
- r += real;
- l+=real;
- for (int x:
- tree) {
- System.out.print(x + " ");
- }
- System.out.println();
- while (r >= l){
- if (r % 2 == 0){
- sum += tree[r];
- r--;
- }
- if (l % 2 == 1){
- sum += tree[l];
- l++;
- }
- l/=2;
- r/=2;
- }
- System.out.println(sum);
- }
- }
- }
- }
- }
- class Pair implements Comparable<Pair>{
- int x;
- int y;
- Pair(int x, int y){
- this.x = x;
- this.y = y;
- }
- @Override
- public int compareTo(Pair pair) {
- if (this.x == pair.x) return this.y - pair.y; else return this.x - pair.x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement