-
Notifications
You must be signed in to change notification settings - Fork 0
/
1521. War Games 2.cpp.bak
94 lines (93 loc) · 1.85 KB
/
1521. War Games 2.cpp.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cassert>
#include <cstring>
using namespace std;
int tree[100005];
int N,K;
void update(int x)
{
while(x<=N)
{
tree[x]++;
x+=(x&-x);
}
}
int sum(int x)
{
//cout<<x<<endl;
int s=0;
while(x>0)
{
s+=tree[x];
x-=(x&-x);
}
return s;
}
int main()
{
scanf("%d %d",&N,&K);
memset(tree,0,sizeof(tree));
int x=1;
long long suma=K;
int prev=0;
cout<<K<<endl;
update(K);
int pos=0;
while(x!=N){
int cost=K;
int m=0;
while(cost>0){
//cout<<cost<<endl;
pos=suma+cost;
if(pos>N){
pos=pos%N;
}
if(pos==0){
pos=N;
}
if(suma>pos){
int x=sum(N)-sum(suma);
int y=sum(pos);
//cout<<pos<<" "<<suma<<" "<<1<<" "<<x+y<<endl;
m++;
cost=cost-(cost-(x+y));
}
else if(suma<pos){
int x=sum(pos)-sum(suma);
if(suma==1)
x=sum(pos);
//cout<<pos<<" "<<suma<<" "<<2<<" "<<x<<endl;
m++;
cost=cost-(cost-x);
}
else{
//cout<<"YO"<<endl;
int x=sum(pos);
//cout<<pos<<" "<<suma<<" "<<3<<" "<<x<<endl;
cost=cost-(cost-x);
}
suma=pos;
}
if(suma==0){
cout<<N<<endl;
suma=N;
}
else
cout<<suma<<endl;
update(suma);
x++;
}
}