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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| #include<algorithm> #include<bitset> #include<complex> #include<deque> #include<exception> #include<fstream> #include<functional> #include<iomanip> #include<ios> #include<iosfwd> #include<iostream> #include<istream> #include<iterator> #include<limits> #include<list> #include<locale> #include<map> #include<memory> #include<new> #include<numeric> #include<ostream> #include<queue> #include<set> #include<sstream> #include<stack> #include<stdexcept> #include<streambuf> #include<string> #include<typeinfo> #include<utility> #include<valarray> #include<vector> #include<cctype> #include<cerrno> #include<cfloat> #include<ciso646> #include<climits> #include<clocale> #include<cmath> #include<csetjmp> #include<csignal> #include<cstdarg> #include<cstddef> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #pragma GCC optimize(3) #define pc(ch) (Ftop<100000?Fout[Ftop++]=ch:(fwrite(Fout,1,100000,stdout),Fout[(Ftop=0)++]=ch)) using namespace std; inline int read(){ int res=0,f=1;char ch=getchar(); while(ch<'0'ch>'9'){if(ch=='-') f=-1;ch=getchar();} while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar(); return res*f; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x<10) putchar(x+'0'); else{ write(x/10); putchar(x%10+'0'); } } inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; }
template <typename T> bool rn(T& _v) { bool negative = false; char ch; _v = 0; while (!isdigit(ch = nc()) && ch != EOF) { negative = ch == '-'; }; if (ch == EOF)return false; do { _v *= 10; _v += ch - '0'; } while (isdigit(ch = nc())); if (negative) _v = -_v; return true; }
template <class T> inline void o(T p) { static int stk[70], tp; if (p == 0) { putchar('0'); return; } if (p < 0) { p = -p; putchar('-'); } while (p) stk[++tp] = p % 10, p /= 10; while (tp) putchar(stk[tp--] + '0'); } int n,m,k,a[500010],f[41][500011]; signed main(){ rn(n);rn(m);rn(k); register int i,j,Ta,b; for(i=1;i<=(n>>1);i++){ a[(i<<1)]=(n>>1)+i,a[(i<<1)-1]=i; } for(i=1;i<=n;i++){ f[0][i]=(i<=k%n)?a[n-k+i]:a[i-(k%n)]; } for(i=1;i<40;i++){ for(j=1;j<=n;j++){ f[i][j]=f[i-1][(f[i-1][j])]; } } long long res=0,tot=0; for(i=1;i<=m;i++){ rn(Ta);rn(b); tot+=Ta; res=tot; for(j=0;res;res>>=1,j++){ if(res&1ll) b=f[j][b]; } o(b);putchar('\n'); } return 0; }
|