-
Notifications
You must be signed in to change notification settings - Fork 0
/
RRSUM.c
52 lines (46 loc) · 1014 Bytes
/
RRSUM.c
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
#include <stdio.h>
char _str[10];
#define READ_INT(_x) \
{ \
unsigned int _tmp = 0; \
register int _ch = getchar_unlocked(); \
while (_ch < 48 || _ch > 57) \
_ch = getchar_unlocked(); \
while (48 <= _ch && _ch <= 57) \
{ \
_tmp = (_tmp << 3) + (_tmp << 1) + _ch - 48; \
_ch = getchar_unlocked(); \
} \
(_x) = _tmp; \
} \
#define WRITE_INT(_x) \
{ \
register int _i = 0; \
int _tmp = (_x); \
do \
{ \
*(_str + _i++) = _tmp % 10 + 48; \
_tmp /= 10; \
} while (_tmp != 0); \
for (_i--; _i >= 0; _i--) \
putchar_unlocked(*(_str + _i)); \
} \
int main(void)
{
unsigned int q;
int m, n;
READ_INT(n);
READ_INT(m);
while (m--)
{
READ_INT(q);
if (q <= n + 1)
putchar_unlocked('0');
else if ((q -= (n + 1)) <= n)
WRITE_INT(q)
else
WRITE_INT((n << 1) - q);
putchar_unlocked('\n');
}
return 0;
}