#include<bits/stdc++.h> #define ALL(X) X.begin(),X.end() #define FOR(I,A,B) for(int (I) = (A); (I) <= (B); (I)++) #define FORW(I,A,B) for(int (I) = (A); (I) < (B); (I)++) #define FORD(I,A,B) for(int (I) = (A); (I) >= (B); (I)--) #define CLEAR(X) memset(X,0,sizeof(X)) #define PB push_back #define MP make_pair #define X first #define Y second using namespace std; typedef signed long long slong; typedef long double ldouble; const slong Infinity = 1000000100; const ldouble Epsilon = 1e-9; /*template<typename T, typename U> ostream& operator << (ostream& os, const pair<T,U>&p) {return os << "(" << p.X << "," << p.Y << ")"; } template<typename T> ostream& operator << (ostream &os, const vector<T>& V) { os << "["; FORW(i,0,size(V)) os << V[i] << ((i==size(V)-1) ? "" : ","); return os << "]"; } template<typename T> ostream& operator << (ostream &os, const set<T>& S) {os << "("; for(auto i: S) os << i << (i==*S.rbegin()?"":","); return os << ")"; } template<typename T, typename U> ostream& operator << (ostream &os, const map<T, U>& M){os << "{"; for(auto i: M) os << i << (i.X==M.rbegin()->X?"":","); return os << "}"; } template<typename T, typename F> T lbound(T p, T q, F f) { static_assert(is_integral<T>::value, "integral type required"); while(p < q) { T r = p+(q-p)/2; if(f(r)) q = r; else p = r+1; } return p; } template<typename T, typename F> T lboundl(T p, T q, F f) { static_assert(is_floating_point<T>::value, "floating point type required"); FOR(i,1,70) { T r = (p+q)/2; if(f(r)) q = r; else p = r; } return p; } template<typename T, typename U> bool contain(T t, U u) { return t.find(u) != t.end(); } template<typename T> int size(T t) { return t.size(); } */ const int MAXN = 500100; int A[MAXN]; int X[MAXN]; int Y[MAXN]; vector<int> Q[MAXN]; int N, K; const int M = 1<<19; pair<int,int> T[2*M]; void read_data() { scanf("%d %d", &N, &K); FOR(i,1,N) scanf("%d", A+i); FOR(i,1,K) scanf("%d %d", X+i, Y+i); } pair<int,int> operator * (pair<int,int> a, pair<int,int> b) { if(a.X == b.X) return MP(a.X, a.Y+b.Y); else if(a.Y > b.Y) return MP(a.X, a.Y-b.Y); else return MP(b.X, b.Y-a.Y); } void make_tree() { FOR(i,1,N) T[i+M] = MP(A[i],1); FORD(i,M-1,1) T[i] = T[2*i] * T[2*i+1]; } int query(int p, int q) { p += M; q += M; pair<int,int> R = T[p]; if(p != q) R = R*T[q]; while(p/2 != q/2) { if(p%2 == 0) R = R*T[p+1]; if(q%2 == 1) R = R*T[q-1]; p /= 2; q /= 2; } return R.X; } void solve() { make_tree(); FOR(i,1,N) Q[A[i]].PB(i); FOR(i,1,K) { int result = 0; int q = query(X[i],Y[i]); vector<int>::iterator l = lower_bound(ALL(Q[q]),X[i]); vector<int>::iterator r = upper_bound(ALL(Q[q]),Y[i]); if(2*(r-l) > Y[i]-X[i]+1) result = q; printf("%d\n", result); } } int L[M*2]; int R[2*M]; void f(int p, int q) { p += M; q += M; vector<pair<int,int> > P; P.PB(MP(L[p],R[p])); if(p != q) P.PB(MP(L[q],R[q])); while(p/2 != q/2) { if(p%2 == 0) P.PB(MP(L[p+1],R[p+1])); if(q%2 == 1) P.PB(MP(L[q-1],R[q-1])); p /= 2; q /= 2; } sort(ALL(P)); FORW(i,0,P.size()) cout << P[i].X << " " << P[i].Y << endl; } int main() { int W[44]; W[0] = 0; W[1] = 1; FOR(i,2,43) W[i] = W[i-1] + W[i-2]; int n; int z; scanf("%d", &z); FOR(_,1,z) { scanf("%d", &n); bool result = false; FOR(i,1,43) FOR(j,1,43) if(slong(W[i])*W[j] == n) result = true; if(result) printf("TAK\n"); else printf("NIE\n"); } return 0; FORW(i,0,M) L[i+M] = R[i+M] = i; FORD(i,M-1,1) {L[i] = L[2*i]; R[i] = R[2*i+1]; } int QQ = 10000; scanf("%d", &QQ); FORW(i,0,QQ) { int a, b; scanf("%d %d", &a, &b); f(a,b); } // read_data(); // solve(); return 0; }
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | #include<bits/stdc++.h> #define ALL(X) X.begin(),X.end() #define FOR(I,A,B) for(int (I) = (A); (I) <= (B); (I)++) #define FORW(I,A,B) for(int (I) = (A); (I) < (B); (I)++) #define FORD(I,A,B) for(int (I) = (A); (I) >= (B); (I)--) #define CLEAR(X) memset(X,0,sizeof(X)) #define PB push_back #define MP make_pair #define X first #define Y second using namespace std; typedef signed long long slong; typedef long double ldouble; const slong Infinity = 1000000100; const ldouble Epsilon = 1e-9; /*template<typename T, typename U> ostream& operator << (ostream& os, const pair<T,U>&p) {return os << "(" << p.X << "," << p.Y << ")"; } template<typename T> ostream& operator << (ostream &os, const vector<T>& V) { os << "["; FORW(i,0,size(V)) os << V[i] << ((i==size(V)-1) ? "" : ","); return os << "]"; } template<typename T> ostream& operator << (ostream &os, const set<T>& S) {os << "("; for(auto i: S) os << i << (i==*S.rbegin()?"":","); return os << ")"; } template<typename T, typename U> ostream& operator << (ostream &os, const map<T, U>& M){os << "{"; for(auto i: M) os << i << (i.X==M.rbegin()->X?"":","); return os << "}"; } template<typename T, typename F> T lbound(T p, T q, F f) { static_assert(is_integral<T>::value, "integral type required"); while(p < q) { T r = p+(q-p)/2; if(f(r)) q = r; else p = r+1; } return p; } template<typename T, typename F> T lboundl(T p, T q, F f) { static_assert(is_floating_point<T>::value, "floating point type required"); FOR(i,1,70) { T r = (p+q)/2; if(f(r)) q = r; else p = r; } return p; } template<typename T, typename U> bool contain(T t, U u) { return t.find(u) != t.end(); } template<typename T> int size(T t) { return t.size(); } */ const int MAXN = 500100; int A[MAXN]; int X[MAXN]; int Y[MAXN]; vector<int> Q[MAXN]; int N, K; const int M = 1<<19; pair<int,int> T[2*M]; void read_data() { scanf("%d %d", &N, &K); FOR(i,1,N) scanf("%d", A+i); FOR(i,1,K) scanf("%d %d", X+i, Y+i); } pair<int,int> operator * (pair<int,int> a, pair<int,int> b) { if(a.X == b.X) return MP(a.X, a.Y+b.Y); else if(a.Y > b.Y) return MP(a.X, a.Y-b.Y); else return MP(b.X, b.Y-a.Y); } void make_tree() { FOR(i,1,N) T[i+M] = MP(A[i],1); FORD(i,M-1,1) T[i] = T[2*i] * T[2*i+1]; } int query(int p, int q) { p += M; q += M; pair<int,int> R = T[p]; if(p != q) R = R*T[q]; while(p/2 != q/2) { if(p%2 == 0) R = R*T[p+1]; if(q%2 == 1) R = R*T[q-1]; p /= 2; q /= 2; } return R.X; } void solve() { make_tree(); FOR(i,1,N) Q[A[i]].PB(i); FOR(i,1,K) { int result = 0; int q = query(X[i],Y[i]); vector<int>::iterator l = lower_bound(ALL(Q[q]),X[i]); vector<int>::iterator r = upper_bound(ALL(Q[q]),Y[i]); if(2*(r-l) > Y[i]-X[i]+1) result = q; printf("%d\n", result); } } int L[M*2]; int R[2*M]; void f(int p, int q) { p += M; q += M; vector<pair<int,int> > P; P.PB(MP(L[p],R[p])); if(p != q) P.PB(MP(L[q],R[q])); while(p/2 != q/2) { if(p%2 == 0) P.PB(MP(L[p+1],R[p+1])); if(q%2 == 1) P.PB(MP(L[q-1],R[q-1])); p /= 2; q /= 2; } sort(ALL(P)); FORW(i,0,P.size()) cout << P[i].X << " " << P[i].Y << endl; } int main() { int W[44]; W[0] = 0; W[1] = 1; FOR(i,2,43) W[i] = W[i-1] + W[i-2]; int n; int z; scanf("%d", &z); FOR(_,1,z) { scanf("%d", &n); bool result = false; FOR(i,1,43) FOR(j,1,43) if(slong(W[i])*W[j] == n) result = true; if(result) printf("TAK\n"); else printf("NIE\n"); } return 0; FORW(i,0,M) L[i+M] = R[i+M] = i; FORD(i,M-1,1) {L[i] = L[2*i]; R[i] = R[2*i+1]; } int QQ = 10000; scanf("%d", &QQ); FORW(i,0,QQ) { int a, b; scanf("%d %d", &a, &b); f(a,b); } // read_data(); // solve(); return 0; } |