#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <exception> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <regex> #include <set> #include <sstream> #include <stdexcept> #include <string> #include <tuple> #include <typeinfo> #include <vector> #include <unordered_set> #include <unordered_map> #include <bitset> using namespace std; #define rep(i,b) for(auto i=(0);i<(b);++i) #define fo(i,a,b) for(auto i=(a);i<=(b);++i) #define ford(i,a,b) for(auto i=(a);i>=(b);--i) #define fore(a,b) for(auto &a:(b)) #define v vector #define pb push_back #define all(x) (x).begin(),(x).end() #define clr(x,a) memset(x,a,sizeof(x)) template <typename T, size_t N> struct ma : array<T,N> { T& operator[](size_t n) { #ifdef DEBUG assert(n < N); #endif return (*static_cast<array<T,N>*>(this))[n]; } } ; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<string> vs; typedef ostringstream oss; typedef istringstream iss; template<class T> string to_str(const T &a) { oss os; os << a; return os.str(); } template<> string to_str<ld>(const ld& a) { oss os; os.precision(10); os.setf(ios::fixed); os << a; return os.str(); } template<class T> T from_str(const string &s) { iss is; T val; is >> val; return val; } int cond = (ll)0; //#define db(x...) { if (cond > 0) { rep (xxx, 1) cerr << __LINE__ << " " << #x << " " << x << endl; cerr.flush(); } } #define db(x...) const int P = (int)1e9 + 7; typedef array<int, 2> pii; typedef array<int, 3> dat; const int sz = 2*(int)1e6 + 33; pii wyn[sz]; map<int, dat> info; map<int, pii, greater<int>> sum; int used[sz]; void dodaj(int pos, int cnt) { pii val = wyn[pos]; if (val[0] < 0) return; used[pos] += cnt; auto &it = sum[val[0]]; it[1] += val[1] * cnt; it[0] += cnt; while (it[1] < 0) it[1] += P; while (it[1] >= P) it[1] -= P; if (it[0] == 0) sum.erase(val[0]); } const int cond2 = 0; const int cond3 = 0; int n; void solve() { v<array<int,2>> a(n+1); fo (i, 1, n) rep(j,2) scanf("%d", &a[i][j]); fo (i, 1, n) wyn[i][0] = -1; wyn[0][0] = 0; wyn[0][1] = 1; info[0] = dat({{(int)1e7, 0, 0}}); vi le(n+1, 0); multiset<int> limit; map<int, vi> rem; fo (i, 1, n) { limit.insert(a[i][1]); rem[i+a[i][1]].pb(a[i][1]); if (!limit.empty()) { int cand = i - *limit.begin(); le[i] = max(le[i], max(0, cand)); } le[i] = max(le[i], le[i-1]); auto pt = rem.find(i); if (pt != rem.end()) { fore (it, pt->second) { limit.erase(limit.find(it)); } } } #define f first #define s second map<int, vector<int>> do_try; int lam = 0; int cnt = 0; fo (i, 1, n) { info[i] = dat{{a[i][0], 1, 0}}; #define iiii map<int, dat>::iterator bool change = false; auto hmm = [&](iiii it2) { lam++; while (true) { again:; if (it2 == info.begin()) break;; auto pr2 = it2; pr2--; auto &it = it2->s; auto &pr = pr2->s; if (it[1] == 0 && it[2] == 0) { cerr<<it2->f<<" "<<__LINE__<<" "<<"BUG"<<endl; exit(1); } int &zab = it[1]; while (pr[1] == 0 && pr[2] > 0) { change = true; if (cond2) cerr << "cond2 " << __LINE__ << endl; db(pr2->f<<" "<<pr[0]<<" "<<pr[1]<<" "<<pr[2]); db(it2->f<<" "<<it[0]<<" "<<it[1]<<" "<<it[2]); db("join"); it[1] += pr[1]; it[2] += pr[2]; db(it2->f<<" "<<it[0]<<" "<<it[1]<<" "<<it[2]); int val = it2->f; db("erase "<<pr2->f); info.erase(pr2->f); it2 = info.find(val); goto again; } if (zab > 0) { int tarzab = max(0, it2->f + (it[0] - 1) - i); db(tarzab<<" "<<zab); db(pr2->f<<" "<<pr[0]<<" "<<pr[1]<<" "<<pr[2]); db(it2->f<<" "<<it[0]<<" "<<it[1]<<" "<<it[2]); while (zab > tarzab) { db(zab<<" "<<tarzab<<" "<<sum.size()); int pos = it2->f - zab; db("dodaj "<<pos); dodaj(pos, 1); zab--; it[2]++; if (cond2) cerr << "cond2 " << __LINE__ << endl; change = true; } while (true) { bool redo = false; while (zab < tarzab && it[2] > 0) { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; db(zab<<" "<<it[2]); int pos = it2->f - zab - 1; db("usun "<<pos); dodaj(pos, -1); zab++; it[2]--; redo = true; } if (redo) continue; //int diff = (it[0] - pr[0]);; int diff = (it[0] - pr[0]);// + (-it2->f + pr2->f); db(it2->f<<" "<<pr2->f<<" "<<diff<<" "<<zab<<" "<<tarzab<<" "<<it[0]<<" "<<pr[0]); if (zab < tarzab && diff >= 0 ) { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; if (it[2] != 0) cerr << "BUG" << endl; it[1] += pr[1]; it[2] += pr[2]; int val = it2->f; db("erase "<<pr2->f); info.erase(pr2->f); it2 = info.find(val); goto again; } if (!redo) break; } db(it2->f<<" "<<it[0]<<" "<<it[1]<<" "<<it[2]); } int minle = it2->f - it[1] - it[2]; while (le[i] > minle || it[1] == 0 && it[2] == 0) { if (it[2] > 0) { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; int pos = it2->f - it[1] - it[2]; db("usun " << pos); dodaj(pos, -1); it[2]--; minle++; } else if (it[1] > 0) { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; int pos = it2->f - it[1]; it[1]--; minle++; } else { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; int val = pr2->f; db("erase "<<it2->f); info.erase(it2->f); it2 = info.find(val); goto again; } } break; } if (change && it2->s[2] == 0 && it2->s[1] > 0) { int pos = it2->f - it2->s[2]; int when = pos + it2->f; if (when > i) do_try[when].pb(it2->f); //do_try[when+1].pb(it2->f); //do_try[it2->f + it2->s[0]].pb(it2->f); } else if (change) { do_try[i+1].pb(it2->f); } return it2; }; int ile = min(50, 20000000 / n); int k = 0; auto it2 = info.begin(); do_try[i].pb(i); do_try[i+a[i][1]].pb(i); do_try[i+a[i][1]+1].pb(i); fo (x, le[i-1], le[i]+1) { //cnt++; auto it2 = info.lower_bound(x); if (it2 == info.end()) break; x = it2->f; do_try[i].pb(it2->f); } //if (i % 1000 == 0) cerr << i<<" "<<do_try[i].size() <<" "<<cnt<< " "<<lam<<endl; fore (it, do_try[i]) { cnt++; if (cond3) cerr<<i<<" "<<it<<endl; bool c2 = 1; rep (iii, 3) { here:; it2 = info.lower_bound(it); if (it2 == info.end()) continue; if (iii == 1) { it2++; if (it2 == info.end()) continue; } if (iii == 2) { if (it2 == info.begin()) continue; it2--; if (it2 == info.begin()) continue; } if (cond3) cerr << "try " <<i<<" "<<it2->f << endl; int k = 0; for (; it2 != info.end(); it2++) { if (it2 == info.begin()) break; do{ change = false; it2 = hmm (it2); if (cond3 && change) { cerr << i <<" "<<it << endl; } if (change) goto here; } while (change); //if (change) cerr << "OK " << it2->f <<endl; //if (! if (change) { k = 0; } else if (k++ > 2) break; } } } do_try.erase(i); k = 0; if (cond2) fore (it, info) cerr <<" HAVE " << i << " " <<it.f << endl; for (; it2 != info.end(); it2++) { change = false; it2 = hmm (it2); if (change) { cerr << "BUG " <<" "<<i<<" "<<it2->f << endl; exit(1); } if (change) k = 0; if (!(change || k++ < 10)) break; } k = 0; if (it2 != info.end()) for (auto it2 = info.end(); it2 != info.begin(); it2--) { if (it2 == info.end()) continue; change = false; it2 = hmm (it2); if (change) { cerr << "BUG " <<" "<<i<<" "<<it2->f << endl; exit(1); } if (change) k = 0; if (!(change || k++ < 10)) break; } /* for (auto it2 = info.begin(); it2 != info.end(); it2++) { change = false; int val = it2->f; if (cond3) cerr <<__LINE__ << endl; it2 = hmm (it2); if (change) { cerr << "hnm " << " " << i <<" " << val<<" "<<it2->f << endl; exit(1); } } */ if (sum.size()) { auto elem = sum.begin(); wyn[i] = pii({{elem->f + 1, elem->s[1]}}); } if (cond) { for (auto it2 = info.begin(); it2 != info.end(); it2++) { db(it2->f<<" "<<it2->s[0]<<" "<<it2->s[1]<<" "<<it2->s[2]); } db(i<<" "<<wyn[i][0]<<" "<<wyn[i][1]); } if (cond) { fo (i, 0, n - 1) if (used[i]) cerr << "(" << i <<" "<<used[i] <<") " ; cerr <<endl; fore (it, sum) { db(i<<" "<<it.f<<" "<<it.s[0]<<" "<<it.s[1]); } } } if (wyn[n][0] == -1) cout << "NIE" << endl; else cout << wyn[n][0] << " " << wyn[n][1] << endl; } void solveb() { v<array<int,2>> a(n); rep (i, n) rep(j,2) scanf("%d", &a[i][j]); vi len(n+1, -2); vi ile(n+1, -1); len[0] = 0; ile[0] = 1; const int MOD = (int)1e9 + 7; ll cntx = 0; fo (i, 1, n) { if (i % 1000 == 0 ) cerr << i << " " << cntx << endl; int mi = a[i-1][0]; int ma = a[i-1][1]; int sum = 0; int best_len = -1; int elem = 0; int cnt = 0; ford (j, i, 1) { elem ++; mi = max(mi, a[j-1][0]); ma = min(ma, a[j-1][1]); if (mi <= ma) { if (elem > ma) break; if (elem >= mi) { if (best_len < len[j-1] + 1 && ile[j-1] >= 0) { best_len = len[j-1] + 1; sum = 0; } if (best_len == len[j-1] + 1) { cntx++; sum = (sum + ile[j-1]) % MOD; } } } else break; } if (best_len > 0) { len[i] = best_len; ile[i] = sum; } db(i<<" "<<best_len<<" "<<sum); } if (len[n] <= -1) cout << "NIE" << endl; else cout << len[n] <<" "<<ile[n]<<endl; } int main(int argc, char ** argv) { ios::sync_with_stdio(false); vs args; int nr_test = -1; int t = 1; int brute = 0; fo (i, 1, argc - 1) args.pb(argv[i]); fore (it, args) if (it == "q") cond = 1000000; fore (it, args) if (it == "all") t = 1000; fore (it, args) if (it == "b") brute = 1; fore (it, args) if (atoi(it.c_str()) > 0) nr_test = atoi(it.c_str()); scanf("%d", &n); fo (i, 1, t) { if (n <= 2000) //brute) solveb(); else 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | #include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <exception> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <regex> #include <set> #include <sstream> #include <stdexcept> #include <string> #include <tuple> #include <typeinfo> #include <vector> #include <unordered_set> #include <unordered_map> #include <bitset> using namespace std; #define rep(i,b) for(auto i=(0);i<(b);++i) #define fo(i,a,b) for(auto i=(a);i<=(b);++i) #define ford(i,a,b) for(auto i=(a);i>=(b);--i) #define fore(a,b) for(auto &a:(b)) #define v vector #define pb push_back #define all(x) (x).begin(),(x).end() #define clr(x,a) memset(x,a,sizeof(x)) template <typename T, size_t N> struct ma : array<T,N> { T& operator[](size_t n) { #ifdef DEBUG assert(n < N); #endif return (*static_cast<array<T,N>*>(this))[n]; } } ; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<string> vs; typedef ostringstream oss; typedef istringstream iss; template<class T> string to_str(const T &a) { oss os; os << a; return os.str(); } template<> string to_str<ld>(const ld& a) { oss os; os.precision(10); os.setf(ios::fixed); os << a; return os.str(); } template<class T> T from_str(const string &s) { iss is; T val; is >> val; return val; } int cond = (ll)0; //#define db(x...) { if (cond > 0) { rep (xxx, 1) cerr << __LINE__ << " " << #x << " " << x << endl; cerr.flush(); } } #define db(x...) const int P = (int)1e9 + 7; typedef array<int, 2> pii; typedef array<int, 3> dat; const int sz = 2*(int)1e6 + 33; pii wyn[sz]; map<int, dat> info; map<int, pii, greater<int>> sum; int used[sz]; void dodaj(int pos, int cnt) { pii val = wyn[pos]; if (val[0] < 0) return; used[pos] += cnt; auto &it = sum[val[0]]; it[1] += val[1] * cnt; it[0] += cnt; while (it[1] < 0) it[1] += P; while (it[1] >= P) it[1] -= P; if (it[0] == 0) sum.erase(val[0]); } const int cond2 = 0; const int cond3 = 0; int n; void solve() { v<array<int,2>> a(n+1); fo (i, 1, n) rep(j,2) scanf("%d", &a[i][j]); fo (i, 1, n) wyn[i][0] = -1; wyn[0][0] = 0; wyn[0][1] = 1; info[0] = dat({{(int)1e7, 0, 0}}); vi le(n+1, 0); multiset<int> limit; map<int, vi> rem; fo (i, 1, n) { limit.insert(a[i][1]); rem[i+a[i][1]].pb(a[i][1]); if (!limit.empty()) { int cand = i - *limit.begin(); le[i] = max(le[i], max(0, cand)); } le[i] = max(le[i], le[i-1]); auto pt = rem.find(i); if (pt != rem.end()) { fore (it, pt->second) { limit.erase(limit.find(it)); } } } #define f first #define s second map<int, vector<int>> do_try; int lam = 0; int cnt = 0; fo (i, 1, n) { info[i] = dat{{a[i][0], 1, 0}}; #define iiii map<int, dat>::iterator bool change = false; auto hmm = [&](iiii it2) { lam++; while (true) { again:; if (it2 == info.begin()) break;; auto pr2 = it2; pr2--; auto &it = it2->s; auto &pr = pr2->s; if (it[1] == 0 && it[2] == 0) { cerr<<it2->f<<" "<<__LINE__<<" "<<"BUG"<<endl; exit(1); } int &zab = it[1]; while (pr[1] == 0 && pr[2] > 0) { change = true; if (cond2) cerr << "cond2 " << __LINE__ << endl; db(pr2->f<<" "<<pr[0]<<" "<<pr[1]<<" "<<pr[2]); db(it2->f<<" "<<it[0]<<" "<<it[1]<<" "<<it[2]); db("join"); it[1] += pr[1]; it[2] += pr[2]; db(it2->f<<" "<<it[0]<<" "<<it[1]<<" "<<it[2]); int val = it2->f; db("erase "<<pr2->f); info.erase(pr2->f); it2 = info.find(val); goto again; } if (zab > 0) { int tarzab = max(0, it2->f + (it[0] - 1) - i); db(tarzab<<" "<<zab); db(pr2->f<<" "<<pr[0]<<" "<<pr[1]<<" "<<pr[2]); db(it2->f<<" "<<it[0]<<" "<<it[1]<<" "<<it[2]); while (zab > tarzab) { db(zab<<" "<<tarzab<<" "<<sum.size()); int pos = it2->f - zab; db("dodaj "<<pos); dodaj(pos, 1); zab--; it[2]++; if (cond2) cerr << "cond2 " << __LINE__ << endl; change = true; } while (true) { bool redo = false; while (zab < tarzab && it[2] > 0) { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; db(zab<<" "<<it[2]); int pos = it2->f - zab - 1; db("usun "<<pos); dodaj(pos, -1); zab++; it[2]--; redo = true; } if (redo) continue; //int diff = (it[0] - pr[0]);; int diff = (it[0] - pr[0]);// + (-it2->f + pr2->f); db(it2->f<<" "<<pr2->f<<" "<<diff<<" "<<zab<<" "<<tarzab<<" "<<it[0]<<" "<<pr[0]); if (zab < tarzab && diff >= 0 ) { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; if (it[2] != 0) cerr << "BUG" << endl; it[1] += pr[1]; it[2] += pr[2]; int val = it2->f; db("erase "<<pr2->f); info.erase(pr2->f); it2 = info.find(val); goto again; } if (!redo) break; } db(it2->f<<" "<<it[0]<<" "<<it[1]<<" "<<it[2]); } int minle = it2->f - it[1] - it[2]; while (le[i] > minle || it[1] == 0 && it[2] == 0) { if (it[2] > 0) { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; int pos = it2->f - it[1] - it[2]; db("usun " << pos); dodaj(pos, -1); it[2]--; minle++; } else if (it[1] > 0) { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; int pos = it2->f - it[1]; it[1]--; minle++; } else { change = true; if (cond2)cerr << "cond2 " << __LINE__ << endl; int val = pr2->f; db("erase "<<it2->f); info.erase(it2->f); it2 = info.find(val); goto again; } } break; } if (change && it2->s[2] == 0 && it2->s[1] > 0) { int pos = it2->f - it2->s[2]; int when = pos + it2->f; if (when > i) do_try[when].pb(it2->f); //do_try[when+1].pb(it2->f); //do_try[it2->f + it2->s[0]].pb(it2->f); } else if (change) { do_try[i+1].pb(it2->f); } return it2; }; int ile = min(50, 20000000 / n); int k = 0; auto it2 = info.begin(); do_try[i].pb(i); do_try[i+a[i][1]].pb(i); do_try[i+a[i][1]+1].pb(i); fo (x, le[i-1], le[i]+1) { //cnt++; auto it2 = info.lower_bound(x); if (it2 == info.end()) break; x = it2->f; do_try[i].pb(it2->f); } //if (i % 1000 == 0) cerr << i<<" "<<do_try[i].size() <<" "<<cnt<< " "<<lam<<endl; fore (it, do_try[i]) { cnt++; if (cond3) cerr<<i<<" "<<it<<endl; bool c2 = 1; rep (iii, 3) { here:; it2 = info.lower_bound(it); if (it2 == info.end()) continue; if (iii == 1) { it2++; if (it2 == info.end()) continue; } if (iii == 2) { if (it2 == info.begin()) continue; it2--; if (it2 == info.begin()) continue; } if (cond3) cerr << "try " <<i<<" "<<it2->f << endl; int k = 0; for (; it2 != info.end(); it2++) { if (it2 == info.begin()) break; do{ change = false; it2 = hmm (it2); if (cond3 && change) { cerr << i <<" "<<it << endl; } if (change) goto here; } while (change); //if (change) cerr << "OK " << it2->f <<endl; //if (! if (change) { k = 0; } else if (k++ > 2) break; } } } do_try.erase(i); k = 0; if (cond2) fore (it, info) cerr <<" HAVE " << i << " " <<it.f << endl; for (; it2 != info.end(); it2++) { change = false; it2 = hmm (it2); if (change) { cerr << "BUG " <<" "<<i<<" "<<it2->f << endl; exit(1); } if (change) k = 0; if (!(change || k++ < 10)) break; } k = 0; if (it2 != info.end()) for (auto it2 = info.end(); it2 != info.begin(); it2--) { if (it2 == info.end()) continue; change = false; it2 = hmm (it2); if (change) { cerr << "BUG " <<" "<<i<<" "<<it2->f << endl; exit(1); } if (change) k = 0; if (!(change || k++ < 10)) break; } /* for (auto it2 = info.begin(); it2 != info.end(); it2++) { change = false; int val = it2->f; if (cond3) cerr <<__LINE__ << endl; it2 = hmm (it2); if (change) { cerr << "hnm " << " " << i <<" " << val<<" "<<it2->f << endl; exit(1); } } */ if (sum.size()) { auto elem = sum.begin(); wyn[i] = pii({{elem->f + 1, elem->s[1]}}); } if (cond) { for (auto it2 = info.begin(); it2 != info.end(); it2++) { db(it2->f<<" "<<it2->s[0]<<" "<<it2->s[1]<<" "<<it2->s[2]); } db(i<<" "<<wyn[i][0]<<" "<<wyn[i][1]); } if (cond) { fo (i, 0, n - 1) if (used[i]) cerr << "(" << i <<" "<<used[i] <<") " ; cerr <<endl; fore (it, sum) { db(i<<" "<<it.f<<" "<<it.s[0]<<" "<<it.s[1]); } } } if (wyn[n][0] == -1) cout << "NIE" << endl; else cout << wyn[n][0] << " " << wyn[n][1] << endl; } void solveb() { v<array<int,2>> a(n); rep (i, n) rep(j,2) scanf("%d", &a[i][j]); vi len(n+1, -2); vi ile(n+1, -1); len[0] = 0; ile[0] = 1; const int MOD = (int)1e9 + 7; ll cntx = 0; fo (i, 1, n) { if (i % 1000 == 0 ) cerr << i << " " << cntx << endl; int mi = a[i-1][0]; int ma = a[i-1][1]; int sum = 0; int best_len = -1; int elem = 0; int cnt = 0; ford (j, i, 1) { elem ++; mi = max(mi, a[j-1][0]); ma = min(ma, a[j-1][1]); if (mi <= ma) { if (elem > ma) break; if (elem >= mi) { if (best_len < len[j-1] + 1 && ile[j-1] >= 0) { best_len = len[j-1] + 1; sum = 0; } if (best_len == len[j-1] + 1) { cntx++; sum = (sum + ile[j-1]) % MOD; } } } else break; } if (best_len > 0) { len[i] = best_len; ile[i] = sum; } db(i<<" "<<best_len<<" "<<sum); } if (len[n] <= -1) cout << "NIE" << endl; else cout << len[n] <<" "<<ile[n]<<endl; } int main(int argc, char ** argv) { ios::sync_with_stdio(false); vs args; int nr_test = -1; int t = 1; int brute = 0; fo (i, 1, argc - 1) args.pb(argv[i]); fore (it, args) if (it == "q") cond = 1000000; fore (it, args) if (it == "all") t = 1000; fore (it, args) if (it == "b") brute = 1; fore (it, args) if (atoi(it.c_str()) > 0) nr_test = atoi(it.c_str()); scanf("%d", &n); fo (i, 1, t) { if (n <= 2000) //brute) solveb(); else solve(); } return 0; } |