-
Notifications
You must be signed in to change notification settings - Fork 3
/
lightoj 1097.cpp
85 lines (73 loc) · 1.36 KB
/
lightoj 1097.cpp
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
#include<bits/stdc++.h>
using namespace std;
#define mx 1429431
void IO()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
}
int ii,n,q;
int Tree[4*mx+5];
void built(int node,int be,int en)
{
if(be==en)
{
Tree[node]=be%2;
return;
}
int mid=(be+en)/2;
built(node*2,be,mid);
built(node*2+1,mid+1,en);
Tree[node]=Tree[node*2]+Tree[node*2+1];
}
int query(int node,int be,int en,int kth)
{
if(be==en )
{
return be;
}
int mid=(be+en)/2;
if(kth<=Tree[node*2])return query(node*2,be,mid,kth);
else return query(node*2+1,mid+1,en,kth-Tree[node*2]);
}
void update(int node,int be,int en,int kth)
{
if(be==en )
{
Tree[node]=0;
return;
}
int mid=(be+en)/2;
if(kth<=Tree[node*2])update(node*2,be,mid,kth);
else update(node*2+1,mid+1,en,kth-Tree[node*2]);
Tree[node]=Tree[node*2]+Tree[node*2+1];
}
void solve()
{
scanf("%d",&n);
printf("Case %d: %d\n",++ii,query(1,1,mx,n) );
}
int main()
{
IO();
built(1,1,mx);
for(int i=2;i<=100000;i++)
{
int pos=query(1,1,mx,i);
int cnt=pos;
while(pos<=mx)
{
update(1,1,mx,pos);
pos+=cnt-1;
}
}
int t;
scanf("%d",&t);
while(t--)
{
solve();
}
return 0;
}