QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358051#3276. 出题高手Froranzen30 425ms40576kbC++148.4kb2024-03-19 16:45:162024-03-19 16:45:16

Judging History

你现在查看的是最新测评结果

  • [2024-03-19 16:45:16]
  • 评测
  • 测评结果:30
  • 用时:425ms
  • 内存:40576kb
  • [2024-03-19 16:45:16]
  • 提交

answer


#include <bits/stdc++.h>
#define rep(i, f, t) for(int i(f); i <= t; ++i)
#define re(i, t) for(int i(1); i <= t; ++i)
#define per(i, t, f) for(int i(t); i >= f; --i)
#define pe(i, t) for(int i(t); i >= 1; --i)
#define ste(i, f, t, s) for(int i(f); i <= t; i += s)
#define ets(i, t, f, s) for(int i(t); i >= f; i -= s)
#define each(i, x) for(auto &i : (x))
#define nx(i, u) for(int i(head[u]); i; i = e[i].nxt) 
typedef long long ll;
typedef long double lb;
typedef unsigned long long ull;
// #define int long long
using namespace std;
// typedef pair <double, int> pdi;
typedef pair <int, int> pii;
// typedef pair <string, bool> psb;
#define pb push_back
#define fi first
#define se second 
#define ix(l, r) ((l + r) | (l != r))
#define ls (ix(l, mid))
#define rs (ix(mid + 1, r))
#define mp(i, j) (make_pair(i, j))
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define i128 __int128
#define exp 1e-7
#define look_memory cerr<<abs(&sT-&eD)/1024.0/1024<<'\n'
int sT;    
 
struct IO {
    #define MAXSIZE 1<<21
    #define isdigit(x) (x >= '0' && x <= '9')
    #define isspace(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
    char ibuf[MAXSIZE], obuf[MAXSIZE], *s1, *s2, *s3, endl, blank;
    int round[10] = {0, 0, 0, 0, 0, 1, 1, 1, 1}, sta[65], precisions;
    bool fail;
    FILE *in_stream, *out_stream;
    IO(FILE *_stream = stdin, FILE *__stream = stdout) { reset(_stream,__stream); }
    #if DEBUG
    #else
        ~IO() {close();}
    #endif
    inline void reset (FILE *_stream = stdin, FILE *__stream = stdout, bool reset = true) {
        s1 = s3 = ibuf, s2 = obuf, in_stream = _stream, out_stream = __stream, fail = false;
        if(reset) { endl = '\n'; blank = ' '; precisions = 6; }
    }
    inline void flush_in() {s3 = (s1 = ibuf) + fread(ibuf, 1, MAXSIZE, in_stream); }
    inline void flush_out() { fwrite(obuf, 1, s2-obuf, out_stream), s2 = obuf; }
    inline void flush_out_with_stream() { flush_out(); fflush(out_stream); } 
    inline char get() {
        #if DEBUG  
            return getchar();
        #endif
        return s1 == s3 && (flush_in(), fail = s1 == s3) ? 0 : *s1++;
    }
    inline void put(char ch) {
        #if DEBUG
            putchar(ch);
        #else
            s2-obuf == MAXSIZE ? flush_out(), 0 : 0, *s2++=ch;
        #endif
    }
    template <class T>
    inline void read(T &x) {
        bool sign = false; char c = get(); x = 0;
        while(!isdigit(c) && c) {sign=c=='-'; c = get(); }
        while(isdigit(c)) { x = (x<<1) + (x<<3) + (c^'0'); c = get(); }
        sign ? x = ~x+1 : 0;
    }
    inline void read(double &x) {
        bool sign = false; char c = get(); x = 0;
        while(!isdigit(c) && c) { sign=c=='-'; c = get(); }
        while(isdigit(c)) { x = x * 10 + (c^'0'); c = get(); }
        if(c=='.') { c = get(); double tmp = 1; while(isdigit(c)) { tmp /= 10, x += tmp * (c^'0'); c = get(); } }
        sign ? x = -x : 0;
    }
    inline void read(long double &x) {
        bool sign = false; register char c = get(); x = 0;
        while(!isdigit(c) && c) { sign=c=='-'; c = get(); }
        while(isdigit(c)) { x = x * 10 + (c^'0'); c = get(); }
        if(c == '.') { c = get(); register long double tmp = 1; while(isdigit(c)) { tmp /= 10, x += tmp * (c^'0'); c = get(); } }
        sign ? x = -x : 0;
    }
    inline void read(char *s) {
        char c = get();
        while(isspace(c)) c = get();
        while(!isspace(c) && c) { *s++=c; c = get(); }
        *s = '\0';
    }
    inline void read(char &c) {
        do
            c = get();
        while(isspace(c));
    }
    template <class T, class ...Args>
    inline void read(T &x, Args &...args) { read(x), read(args...); }
    template <class T>
    inline void write(T x) {
        int top = 0;
        if(x<0) { put('-'); sta[top++] = ~(x%10)+1, x /= 10; x = ~x+1; }
        else sta[top++] = x%10, x /= 10;
        while(x) sta[top++] = x%10 ,x /= 10;
        while(top) put(sta[--top]^'0');
    }
    inline void write(double y) {
        int top = 0;
        if(y<0) { put('-'); y=-y; }
        int x = y; y -=x;
        write(x);
        if(y) {
            do
                sta[top++] = y*10, y = y*10 - sta[top-1];
            while(top<precisions-1);
            sta[top++] = y*10 + round[(int)((y*10-((int)(y*10)))*10)];
        }
        put('.');
        for(int i(0); i<top; ++i) put(sta[i]^'0');
        for(int i(top); i<precisions; ++i) put('0');
    }
    inline void write(long double y) {
        register int top = 0;
        if(y<0) { put('-'); y=-y; }
        int x = y; y -= x;
        write(x);
        if(y) {
            do
                sta[top++] = y*10, y = y*10 - sta[top-1];
            while(top<precisions-1);
            sta[top++] = y*10 + round[(int)((y*10-((int)(y*10)))*10)];
        }
        put('.');
        for(register int i(0); i < top; ++i) put(sta[i]^'0');
        for(register int i(top); i < precisions; ++i) put('0');
    }
    inline void write(const char ch) { put(ch); }
    inline void write(char *s) { while(*s!='\0') put(*s++); }
    inline void write(const char *s) { while(*s!='\0') put(*s++); }
    inline void write(const std::string str) { write(str.c_str()); }
    inline IO &precision(const int x) { precisions=x; return *this; }
    template <class T,class ...Args>
    inline void write(T x,Args ...args) { write(x), blank?put(blank), 0:0, write(args...); }
    template <class ...Args>
    inline void writeln(Args ...args) { write(args...), endl?put(endl), 0:0; }
    template <class T>
    inline IO &operator>>(T &x) { read(x); return *this; }
    inline IO &operator>>(IO &x) { return *this; }
    template <class T>
    inline IO &operator<<(const T x) { write(x); return *this; }
    inline IO &operator<<(IO &x) { return *this; }
    inline operator bool() { return !fail; }
    template <class T>
    inline operator T() { T x; read(x); return x; }
    inline void open(FILE *_stream=stdin,FILE *__stream=stdout) { close(), reset(_stream, __stream, false); }
    inline void close() { flush_out_with_stream(); fclose(in_stream), fclose(out_stream); }
    #define read(x) io>>x
    #define out(x) io<<x
}io;
const int N = 5e5 + 5;
int n, a[N];
int m;
struct Que {
    int id, l, r;
}p[N];

bool cmp (Que a, Que b) {
    return a.r < b.r; 
}

int f[N];
ll ans[N][2], pre[N], tag[N][2], val[N][2];
int sq, bl[N], lth[N], rth[N];

void check (ll a, ll b, ll &x, ll &y) {
    if((i128)1 * a * y >= (i128)1 * b * x) {
        x = a, y = b;
    }
}

void update (int p, ll a, ll b) { 
    check(a, b, tag[bl[p]][0], tag[bl[p]][1]);
    check(a, b, val[p][0], val[p][1]);
}

void query (int id, int l, int r) {
    if(bl[l] + 1 >= bl[r]) {
        rep(i, l, r) check(val[i][0], val[i][1], ans[id][0], ans[id][1]);
        return ;
    }
    rep(i, l, rth[bl[l]]) check(val[i][0], val[i][1], ans[id][0], ans[id][1]);
    rep(i, lth[bl[r]], r) check(val[i][0], val[i][1], ans[id][0], ans[id][1]);
    rep(i, bl[l] + 1, bl[r] - 1) check(tag[i][0], tag[i][1], ans[id][0], ans[id][1]);
}

mt19937 rnd(time(0));

int main () {
    io >> n;
    sq = sqrt(n);
    re(i, n) bl[i] = (i - 1) / sq + 1;
    re(i, bl[n]) {
        lth[i] = rth[i-1] + 1;
        rth[i] = i * sq;
    }
    re(i, n) val[i][0] = tag[i][0] = 0, tag[i][1] = val[i][1] = 1;
    rth[bl[n]] = n;  
    re(r, n) { 
        io >> a[r];
        pre[r] = pre[r-1] + a[r];
        f[r] = r;
        int sum = 0;
        if(a[r] == 0) continue;
        if(a[r] < 0) {
            pe(l, r) {
                sum += a[l];
                if(sum >= 0) break;
                f[r] = l;
            } 
        }
        else {
            pe(l, r) {
                sum += a[l];
                if(sum <= 0) break;
                f[r] = l;
            }
        }
        f[r] = max(f[r], r - sq + 1);
    }
    io >> m; 
    re(i, m) {
        ans[i][0] = 0, ans[i][1] = 1; 
        io >> p[i].l >> p[i].r;
        p[i].id = i;
    } 
    sort(p + 1, p + m + 1, cmp);
    int now = 1;
    re(i, n) {
        per(j, i, f[i]) update(j, 1ll * (pre[i] - pre[j-1]) * (pre[i] - pre[j-1]), i - j + 1);
        while(now <= m && p[now].r == i) {
            query(p[now].id, p[now].l, p[now].r);
            ++now;
        }
    }
    re(i, m) {
        ll w = __gcd(ans[i][0], ans[i][1]);
        ans[i][0] /= w;
        ans[i][1] /= w;
        io << ans[i][0] << " " << ans[i][1] << "\n";
    }
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 24ms
memory: 28372kb

input:

2000
-113 314 -664 697 211 -199 -38 -190 8 -661 910 -811 -113 942 77 433 -261 -368 129 -525 968 -608 -21 38 -562 438 -935 -228 220 333 985 -430 916 586 764 476 794 664 383 503 206 -60 380 -130 -988 -904 -996 -304 -286 31 114 119 850 -942 714 -369 -842 250 -192 -462 -727 -427 -602 126 231 718 121 559...

output:

54826875 11
14638276 7
1185921 1
81018001 24
6310144 3
12545764 5
3362000 1
23068809 8
23068809 8
12545764 5
1444908 1
5424241 3
1083603 1
2140369 1
2752281 2
3095072 1
3003289 2
4959529 2
17106496 13
4780232 1
89605156 31
8543929 4
109809441 44
5094049 2
68591524 23
8543929 4
35688676 11
3775249 1
...

result:

wrong answer 45th numbers differ - expected: '129163225', found: '109809441'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 15
Accepted
time: 28ms
memory: 28932kb

input:

100000
754 792 -680 426 425 347 481 -690 530 378 73 -907 -431 45 -530 -552 440 -890 -15 712 695 -679 -310 13 718 805 193 -291 -877 -74 -355 511 -679 -395 166 -710 -657 -19 874 26 832 507 854 -289 700 -404 472 -302 -977 8 -698 40 766 705 369 838 700 -964 552 -535 -75 -608 -181 -503 468 447 772 904 -2...

output:

466344025 67

result:

ok 2 number(s): "466344025 67"

Test #7:

score: -15
Wrong Answer
time: 40ms
memory: 27084kb

input:

100000
-387 -313 -47 -714 -74 239 8 591 541 -633 -660 981 -230 -148 -813 -802 -108 -543 -640 50 962 137 -972 -936 -975 885 793 -541 932 861 -348 885 -280 -977 -677 964 355 604 54 -977 -548 979 -516 136 437 -697 -23 -748 492 897 -538 785 617 -840 675 -978 307 -288 -493 682 678 -623 613 762 -622 -283 ...

output:

369062521 61

result:

wrong answer 1st numbers differ - expected: '2417885584', found: '369062521'

Subtask #3:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 322ms
memory: 38364kb

input:

500000
794 -75 -596 -322 -945 -908 -609 -164 488 626 -877 -710 140 -120 -475 -837 738 669 634 -643 -682 667 816 -785 -608 -836 -860 -932 242 70 -620 268 -121 288 209 -392 732 750 558 -480 565 327 -217 -891 767 211 -690 -66 813 -889 952 615 432 19 411 800 678 718 522 422 940 -510 -544 449 -357 640 40...

output:

1878442281 242

result:

ok 2 number(s): "1878442281 242"

Test #12:

score: 0
Accepted
time: 425ms
memory: 40576kb

input:

500000
145 33 695 -456 761 -556 698 272 121 -445 100 -93 954 485 161 798 -279 921 456 570 151 -880 456 -640 -69 385 -301 -707 -84 -514 -964 597 874 346 841 274 -727 -177 -44 -883 903 -792 -776 926 416 -862 -247 -985 518 674 174 535 -295 960 -952 722 -947 -365 366 -520 -60 -404 800 811 -139 779 735 3...

output:

457831609 56

result:

ok 2 number(s): "457831609 56"

Test #13:

score: 0
Accepted
time: 335ms
memory: 40456kb

input:

500000
762 -391 336 983 -962 920 -428 955 487 -525 281 514 851 -508 607 153 -439 -307 345 557 -615 -997 272 813 -556 -69 -401 -625 143 -142 -499 380 749 613 -190 173 -633 -489 -285 183 -799 645 -863 379 169 -177 993 -184 753 346 58 770 254 705 -467 -700 -337 587 -333 685 -1 -618 -961 327 -33 -722 65...

output:

1160015481 110

result:

ok 2 number(s): "1160015481 110"

Test #14:

score: 0
Accepted
time: 290ms
memory: 38528kb

input:

500000
-819 -236 -303 662 -316 -328 51 821 717 -423 -565 -394 858 -816 -246 -993 831 -999 237 779 52 -642 826 945 307 -675 83 -715 -797 -451 -250 996 53 -765 -869 -717 -126 -250 532 -848 82 -100 542 80 798 701 -648 -433 234 362 462 -770 554 -211 -368 -653 897 -940 416 632 734 -18 727 319 -328 697 11...

output:

188897536 23

result:

ok 2 number(s): "188897536 23"

Test #15:

score: 0
Accepted
time: 397ms
memory: 38656kb

input:

500000
-161 619 -969 31 102 781 561 617 -685 -814 385 -998 911 -206 -404 519 276 -318 -731 -908 901 856 839 333 124 481 29 407 -315 -219 896 956 -286 996 -991 -800 951 109 -846 624 750 -88 955 -752 -814 134 -316 -777 844 391 359 -324 789 -713 -620 849 -553 575 357 792 -735 -828 373 378 -213 -501 -29...

output:

167832025 17

result:

ok 2 number(s): "167832025 17"

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 38ms
memory: 29200kb

input:

100000
-496 -233 354 -632 -196 177 -878 -255 -19 -636 685 -70 101 -975 -406 -988 -965 -205 563 -766 763 511 -116 -746 -129 14 106 928 -457 -257 -283 226 3 899 -359 -792 615 490 -57 986 -243 624 -239 931 -555 -821 -72 -611 -380 -397 248 -132 956 -195 -322 -231 319 -214 837 -379 -931 -301 -4 -673 280 ...

output:

1352474176 205
13957947 4
67914081 16
33243858 7
10885778 3
27836176 7
50680161 11
235284921 74
106770889 25
2411809 2
2835045 1
14017536 5
134699236 43
286523329 74
28100601 11
17546888 5
23396569 6
80839443 25
4012009 3
2661336 1
42947912 11
3474284 1
61496964 19
3672245 1
6120676 3
7573504 3
1489...

result:

wrong answer 579th numbers differ - expected: '297606125', found: '348232921'

Subtask #5:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 196ms
memory: 37048kb

input:

100000
139 -485 -497 -818 254 169 -560 22 377 -67 -243 -75 743 -788 -676 -26 -775 371 576 -303 54 733 422 800 445 687 479 -16 -288 259 783 -586 912 616 439 -416 676 -555 172 659 501 -868 337 22 -60 260 603 -982 -149 466 769 -595 -117 949 -544 904 753 20 776 175 -888 937 -792 -647 -615 59 -298 452 -6...

output:

401594700 47
3916125 1
4343056 1
23049601 8
19713600 7
62900761 15
46076944 15
6620329 2
3775805 1
7868025 4
20659592 7
66569281 16
3354050 1
48818169 10
10629610 3
44129449 10
62837329 19
10975969 2
2958400 1
6786025 2
2683044 1
3323047 1
83631025 17
10329796 3
78198649 18
7840000 3
401594700 47
65...

result:

wrong answer 111th numbers differ - expected: '2619187684', found: '184172041'