-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path1027B.cpp
63 lines (61 loc) · 975 Bytes
/
1027B.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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1<<20;
vector<int>v;
ll cnt,a[N],b[N],has[N],n,m,sum,min1,max1;
string s,t;
bool flag;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
while(m--)
{
ll x,y;
cin>>x>>y;
sum=x+y;
if(!(n&1))
{ cnt=0;
cnt+=(n/2)*(x-1);
cnt+=ceil(y/2.0);
if(!(sum&1))
{
cout<<cnt<<endl;
}
else
{
cnt+=n*n/2;
cout<<cnt<<endl;
}
}
else
{ cnt=0;
if(!(sum&1))
{
if(x&1)
{
cnt+=x/2*n+1+(y-1)/2;
}
else
{
cnt+=(x/2)*(n/2+1)+(x/2-1)*(n/2)+(y-2)/2+1;
}
}
else
{
if(x&1)
{
cnt+=n*n/2+1+x/2*n+1+(y-2)/2;
}
else
{
cnt+=n*n/2+1+x/2*(n/2)+(x/2-1)*(n/2+1)+1+(y-1)/2;
}
}
cout<<cnt<<endl;
}
}
return 0;
}
//_4_4_3_//