QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#132705 | #147. Floppy | somethingnew# | 7 | 2ms | 4116kb | C++20 | 5.7kb | 2023-07-31 03:27:18 | 2024-07-04 01:02:33 |
Judging History
floppy
// ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
// ➡ @roadfromroi ⬅
// ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#define all(x) x.begin(), x.end()
using namespace std;
#include "floppy.h"
struct segtree {
int sz;
vector<pair<int, int>> tree;
void init(vector<int> a) {
sz = 1;
while (sz < a.size())
sz *= 2;
tree.assign(sz * 2, {});
for (int i = 0; i < a.size(); ++i) {
tree[i + sz] = {a[i], i};
}
for (int i = sz-1; i >= 1; --i) {
tree[i] = max(tree[i * 2], tree[i * 2 + 1]);
}
}
int getseg(int l, int r) {
l += sz;
r += sz;
pair<int, int> res ={-1,-1};
while (l <= r) {
if (l % 2 == 1) {
res = max(res, tree[l]);l++;
}
if (r % 2 == 0) {
res = max(res, tree[r]);r--;
}
l /= 2;r /= 2;
}
return res.second;
}
};
void mrg(deque<int> &a, deque<int> &b) {
if (a.size() > b.size()) {
while (!b.empty()) {
a.push_back(b.front());
b.pop_front();
}
} else {
while (!a.empty()) {
b.push_front(a.back());
a.pop_back();
}
swap(a, b);
}
}
segtree sg;
void beba(int l, int r, string &boba) {
if (l > r) {
return;
}
int mx = sg.getseg(l, r);
//cout << l << ' ' << r << "->" << mx << endl;
beba(l, mx-1, boba);
boba += '0';
beba(mx+1, r, boba);
boba += '1';
return;
}
void read_array(int subtask_id, const std::vector<int> &v) {
sg.init(v);
string bits;
beba(0, v.size() - 1, bits);
save_to_floppy(bits);
}
vector<int> mytree;
vector<vector<int>> prfsm;
vector<int> actual;
void recareca(int l, int r, int myn, int myg) {
if (l >= r)
return;
int eba = upper_bound(all(prfsm[myg]), r) - prfsm[myg].begin() - 1;
if (eba == -1)
return;
int vl = prfsm[myg][eba];
if (vl > r)
exit(1);
if (vl < l)
return;
mytree[actual[vl]] = myn;
recareca(l, vl-1, myn-1, myg);
recareca(vl+1, r-1, myn-1, myg+1);
}
std::vector<int> solve_queries(int subtask_id, int N,
const std::string &bits,
const std::vector<int> &a, const std::vector<int> &b) {
prfsm.assign(bits.size() + 1, {});
prfsm[0].push_back(0);
mytree.assign(N, {});
int sm = 0;
int reac = 0;
actual.assign(bits.size()+1, {});
for (int i = 0; i < bits.size(); ++i) {
if (bits[i] == '0') {
//cout << "(";
sm++;
reac++;
}else {
//cout << ")";
sm--;
}
actual[i + 1] = reac;
// cout << i+1 << ' ' << sm << ' ';
prfsm[sm].push_back(i+1);
//cout << prfsm[sm].back() << endl;
//cerr << sm << ' ' << i + 1 << endl;
}
recareca(0, bits.size() - 1, N, 0);
sg.init(mytree);
vector<int> res;
for (int i = 0; i < a.size(); ++i) {
res.push_back(sg.getseg(a[i], b[i]));
}
return res;
}
#ifdef __APPLE__
#define NMAX 100000
#define MMAX 100000
int subtask_id, N, M;
std::vector<int> v, sorted_v;
std::vector<int> a, b;
std::vector<int> correct_answers;
// Print score to stdout and exit.
void score_and_exit(const double pts, const char *verdict) {
fprintf(stderr, "%s", verdict);
fprintf(stdout, "%f", pts);
exit(0);
}
// Contestant sent too many bits.
void too_many_bits() {
score_and_exit(0, "Too many stored bits!");
}
// Contestant did not send any bits.
void misformatted_stored_bits() {
score_and_exit(0, "Misformatted stored bits or save_to_floppy not called!");
}
// Contestant did not call the answer function.
void answer_not_provided() {
score_and_exit(0, "Answer not provided!");
}
// Contestant sent a wrong answer.
void wrong_answer() {
score_and_exit(0, "Wrong answer to query!");
}
// Contestant sent a correct answer.
void correct_answer() {
score_and_exit(1, "OK!");
}
void read_test() {
assert(scanf("%d", &subtask_id) == 1);
assert(scanf("%d%d", &N, &M) == 2);
assert(1 <= N && N <= NMAX);
assert(0 <= M && M <= MMAX);
v.resize(N);
for (int i = 0; i < N; ++i) {
v[i] = i * 2;
//assert(scanf("%d", &v[i]) == 1);
}
// Check all values are distinct.
sorted_v.resize(N);
for (int i = 0; i < N; ++i) {
sorted_v[i] = v[i];
}
std::sort(sorted_v.begin(), sorted_v.end());
for (int i = 0; i + 1 < N; ++i) {
assert(sorted_v[i] < sorted_v[i + 1]);
}
a.resize(M);
b.resize(M);
correct_answers.resize(M);
for (int i = 0; i < M; ++i) {
assert(scanf("%d%d%d", &a[i], &b[i], &correct_answers[i]) == 3);
assert(0 <= a[i] && a[i] <= correct_answers[i] &&
correct_answers[i] <= b[i] && b[i] < N);
}
}
void save_to_floppy(const std::string &bits) {
std::vector<int> contestant_answers = solve_queries(subtask_id, N, bits, a, b);
for (int i = 0; i < M; ++i) {
if (contestant_answers[i] != correct_answers[i]) {
wrong_answer();
}
}
correct_answer();
exit(0);
}
int main(int argc, char **argv) {
// Read input data.
read_test();
// Send subtask_id, v.
read_array(subtask_id, v);
answer_not_provided();
return 0;
}
#endif
/*
2
4 1
40 20 30 10
0 0 0
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 2ms
memory: 3848kb
input:
1 496 484 491 478 483 452 446 458 493 453 457 468 418 440 241 267 365 462 441 495 39 54 70 26 97 152 24 105 85 170 298 42 275 305 295 297 207 211 296 184 346 98 123 171 157 135 194 243 156 115 196 169 53 138 93 263 251 201 195 333 324 396 338 270 311 359 289 290 486 403 183 339 310 473 464 471 469 4...
output:
992 01001000110111001010010010101100111100101001101001001110100101100100101001111001010001110100011000100111110000111100111000101100101110001001110010011100100011101001001100010100111111000011101010011001111001001100100110011001011110000101100010011111001000100001111100001011110010010101100001101011...
input:
1 496 992 01001000110111001010010010101100111100101001101001001110100101100100101001111001010001110100011000100111110000111100111000101100101110001001110010011100100011101001001100010100111111000011101010011001111001001100100110011001011110000101100010011111001000100001111100001011110010010101100001...
output:
115 18 115 305 115 18 305 373 115 305 115 373 115 115 305 365 373 461 305 305 18 115 429 201 305 305 115 39 67 18 115 115 305 305 115 373 115 352 67 305 115 373 115 453 18 67 18 305 373 115 115 429 373 252 115 125 115 201 115 491 115 305 115 18 305 305 287 305 115 305 18 201 115 373 370 305 305 201 ...
result:
ok good job! L = 992
Test #2:
score: 7
Accepted
time: 2ms
memory: 4116kb
input:
1 496 466 469 320 402 391 453 73 101 122 49 54 94 93 148 197 168 233 144 125 161 69 34 247 76 37 90 71 33 42 212 188 156 110 135 165 374 277 289 248 273 236 131 210 242 238 231 366 346 314 358 300 349 322 412 315 268 354 340 99 176 290 313 221 229 332 265 269 146 316 403 369 492 190 256 266 100 126 ...
output:
992 01001001100101001010011101001100011000111100011000101110000101101111001001000101100011111000110010011111000110001010100101100100110111100111110010100101010010110110010010111000011100110101001010111000111000001100111111000011100110010010101110001001001011011000011001110110001011110010101011100101...
input:
1 496 992 01001001100101001010011101001100011000111100011000101110000101101111001001000101100011111000110010011111000110001010100101100100110111100111110010100101010010110110010010111000011100110101001010111000111000001100111111000011100110010010101110001001001011011000011001110110001011110010101011...
output:
339 339 339 389 222 339 256 256 339 180 339 339 339 310 109 71 339 365 256 256 171 455 484 264 200 339 256 413 339 339 339 339 339 339 109 339 256 109 339 222 339 339 109 339 109 339 455 346 109 213 339 53 339 339 109 339 339 339 109 339 339 339 339 339 339 109 109 339 256 109 339 256 310 109 339 10...
result:
ok good job! L = 992
Test #3:
score: 7
Accepted
time: 2ms
memory: 4088kb
input:
1 496 487 495 488 494 486 493 490 492 485 491 483 489 484 482 480 481 479 478 477 475 476 473 474 472 470 471 466 469 468 465 467 464 462 463 458 461 459 460 457 456 455 454 453 451 452 449 450 448 447 444 446 445 442 443 441 434 440 438 439 437 435 436 433 431 432 429 430 424 428 423 427 426 422 42...
output:
992 01001001001001001000010000010010001001000100010010010000000100100001000100010010001000100100100100010000010010010010001001001000100001001001001000100100100010010001001001000010010000100010010010010010000010010010000100000100100010010010001000010000100010000100000100010000010000000100100100010010...
input:
1 496 992 01001001001001001000010000010010001001000100010010010000000100100001000100010010001000100100100100010000010010010010001001001000100001001001001000100100100010010001001001000010010000100010010010010010000010010010000100000100100010010010001000010000100010000100000100010000010000000100100100...
output:
157 202 218 223 145 242 85 315 70 15 230 197 261 162 175 175 25 112 225 98 68 319 290 147 247 167 353 360 167 3 22 315 432 353 5 418 313 151 129 58 54 206 151 18 125 227 112 92 73 98 27 91 153 318 400 16 121 234 174 78 244 68 372 242 48 11 5 221 129 194 395 33 263 102 91 172 391 125 112 240 266 349 ...
result:
ok good job! L = 992
Test #4:
score: 7
Accepted
time: 2ms
memory: 4116kb
input:
1 495 473 486 488 489 491 485 477 474 472 480 483 460 459 462 448 447 444 449 454 442 434 437 443 439 433 430 440 438 435 431 429 436 424 421 426 418 422 417 413 416 414 405 409 406 407 403 404 391 392 385 388 387 386 390 384 377 369 382 371 375 374 370 367 368 366 360 362 363 364 352 348 361 354 35...
output:
990 01010101000001110100011000011101000101100001110000011100011001000100010010010010010001110000110010000100010101000110000111001001001001010010100100010100011001100100011000011001100011010001010001100010010100001110000010100011001001100101010001001010000010011100000111000101101001010010010001100100...
input:
1 495 990 01010101000001110100011000011101000101100001110000011100011001000100010010010010010001110000110010000100010101000110000111001001001001010010100100010100011001100100011000011001100011010001010001100010010100001110000010100011001001100101010001001010000010011100000111000101101001010010010001...
output:
290 457 363 400 302 348 463 117 103 109 363 385 53 457 130 13 18 53 126 18 81 446 482 81 409 491 123 18 377 486 277 13 342 98 342 298 486 456 438 361 13 46 382 18 347 293 431 457 44 482 483 75 412 369 483 13 428 483 382 299 430 363 98 486 109 478 306 281 31 331 461 182 446 46 205 87 340 317 356 53 6...
result:
ok good job! L = 990
Test #5:
score: 7
Accepted
time: 2ms
memory: 3828kb
input:
1 498 379 228 234 288 275 306 283 287 302 280 196 162 261 251 312 255 204 405 289 220 265 269 342 148 231 338 296 394 161 267 340 116 218 226 305 186 282 240 391 337 351 366 401 321 333 454 362 396 406 329 380 443 190 292 301 273 358 377 402 398 418 414 450 475 348 354 419 285 291 279 216 262 349 32...
output:
996 00101001100101000011001111100011110001010110010100111001010010101001001111001010111001011100101001011001010011010100110011101100101001000101110011001110011000110010110010110001001010111000101010101011110001010010111001000101111000111000011010001001101100010110010110011111001010101001000111100001...
input:
1 498 996 00101001100101000011001111100011110001010110010100111001010010101001001111001010111001011100101001011001010011010100110011101100101001000101110011001110011000110010110010110001001010111000101010101011110001010010111001000101111000111000011010001001101100010110010110011111001010101001000111...
output:
417 63 362 63 456 372 102 372 63 237 372 289 63 63 372 289 63 102 63 63 63 372 63 63 78 289 162 102 162 289 289 63 372 102 372 63 115 102 372 372 372 138 162 372 372 372 289 372 118 289 372 280 162 63 372 102 372 289 289 372 372 372 362 417 63 372 474 289 63 78 372 268 237 417 372 417 351 63 417 237...
result:
ok good job! L = 996
Subtask #2:
score: 0
Program floppy Memory Limit Exceeded
Test #6:
score: 0
Program floppy Memory Limit Exceeded
input:
2 9998 941669562 945620824 923950848 951745929 487936934 545172907 544098433 249251812 620978276 575815248 584717207 588068187 353162497 679201670 592738155 438327774 762119945 576801563 408534366 592715009 525377786 603981493 -93758897 137509462 -38676966 -36724784 654920761 -595506762 -645387884 -...
output:
input:
output:
result:
Subtask #3:
score: 0
Program floppy Memory Limit Exceeded
Test #11:
score: 0
Program floppy Memory Limit Exceeded
input:
3 39995 922975946 766568552 929754744 983095922 988967630 879723897 928174186 951250463 831467029 836738151 464712826 467214506 167661408 156498284 426000721 530835328 -35115993 -86200136 327603078 448684869 192895652 125768327 402822176 196767853 409109378 985776352 976681898 967347754 989156210 99...