Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- static int generuj(int xi) {
- return ((xi * 25173) + 13849) % 65536;
- }
- public static class Hrac {
- int skill, ktory;
- public Hrac(int skill, int ktory){
- this.skill = skill;
- this.ktory = ktory;
- }
- }
- public static void Zmen(int MM, int M, Hrac[] pole){
- for (int j = 0; j < MM/2; j++) {
- for (int k = M-1; k < (2*M)-2; k=k+2){
- if (pole[k].skill >= pole[k+1].skill) {
- pole[k/2] = new Hrac(pole[k].skill,pole[k].ktory);
- } else {
- pole[k/2] = new Hrac(pole[k+1].skill,pole[k+1].ktory);
- }
- }
- M = M / 2;
- }
- }
- public static void main(String[] args) {
- Scanner input = new Scanner( System.in );
- int N = input.nextInt();
- int M = (int)Math.pow(2,N);
- int MM = M;
- int s0 = input.nextInt();
- Hrac[] pole = new Hrac[(2*M)-1];
- for (int i = 0; i < M; i++){
- int s = generuj(s0);
- s0 = s;
- pole[M-1+i] = new Hrac(s, i+1);
- }
- Zmen(MM,M,pole);
- System.out.println(pole[0].ktory+" "+pole[0].skill);
- int pocet_zmien = input.nextInt();
- for (int i = 0; i < pocet_zmien; i++){
- int zmena_kto = input.nextInt();
- int zmena_skill = input.nextInt();
- M = MM;
- pole[M-1+zmena_kto-1].skill = pole[M-1+zmena_kto-1].skill + zmena_skill;
- int k = M-1+zmena_kto-1;
- int wins = 0;
- for (int j = 0; j < MM/2; j++) {
- if ((k % 2) == 1) {
- if (pole[k].skill >= pole[M-1+zmena_kto].skill){
- pole[k / 2].skill = pole[k].skill;
- pole[k / 2].ktory = pole[k].ktory;
- wins++;
- } else {
- if (zmena_skill < 0) {
- Zmen(MM,MM,pole);
- }
- j = 2*MM;
- }
- } else {
- if (pole[k].skill > pole[M-1+zmena_kto-2].skill){
- pole[(k-1) / 2].skill = pole[k].skill;
- pole[(k-1) / 2].ktory = pole[k].ktory;
- wins++;
- } else {
- if (zmena_skill < 0) {
- Zmen(MM,MM,pole);
- }
- j = 2*MM;
- }
- }
- k = k / 2;
- M = M / 2;
- }
- System.out.println(wins);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement