QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#312189#7992. 【模板】线段树nodgdTL 1727ms4084kbC++143.3kb2024-01-23 16:16:322024-01-23 16:16:33

Judging History

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

  • [2024-01-23 16:16:33]
  • 评测
  • 测评结果:TL
  • 用时:1727ms
  • 内存:4084kb
  • [2024-01-23 16:16:32]
  • 提交

answer

#include <cstdio>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,popcnt,tune=native")
#include <immintrin.h>
#include <emmintrin.h>
#include <algorithm>
#include <ctime>
using namespace std;

typedef unsigned int u32;
typedef unsigned long long u64;
typedef __m128i u128;

////////////////////////////////////////////////////////////////

const int BUFFER_SIZE = 1 << 20;
char rb[BUFFER_SIZE], *rp = rb, *rt = rb;
inline char read_char() {
    return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp ++) : *rp ++;
}
inline u32 read_u32() {
    u32 x = 0;
    char ch = read_char();
    for (; ch < '0' || ch > '9'; ch = read_char());
    for (; ch >= '0' && ch <= '9'; ch = read_char()) x = x * 10 + (ch - '0');
    return x;
}
char wb[BUFFER_SIZE], *wp = wb;
inline void write_flush() {
    fwrite(wb, 1, wp - wb, stdout), wp = wb;
}
inline void write_char(char c) {
    *wp ++ = c;
    if (wp == wb + BUFFER_SIZE) write_flush();
}
inline void write_u32(u32 x) {
    if (x == 0) write_char('0');
    static char b[32], i;
    for (i = 1; x; x /= 10, i ++) b[i] = x % 10 + '0';
    for (i --; i; i --) write_char(b[i]);
}

////////////////////////////////////////////////////////////////

u32 a[200000 + 16];

int main() {
    u32 N = read_u32(), Q = read_u32();
    for (int i = 1; i <= N; i ++) {
        a[i] = read_u32();
    }
    for (int i = 1; i <= Q; i ++) {
        u32 o = read_u32();
        u32 l = read_u32();
        u32 r = read_u32();
        u32 *p = a + l, *q = a + r + 1;
        if (o == 1u) {
            u32 x = read_u32();
            u128 y = _mm_set1_epi32(x);
            for (; ((u64)p & 15u) && p != q; p ++) {
                p[0] += x;
            }
            u32 m = q - p >> 4u;
            for (; m --; p += 16u) {
                ((u128*)p)[0] = _mm_add_epi32(((u128*)p)[0], y);
                ((u128*)p)[1] = _mm_add_epi32(((u128*)p)[1], y);
                ((u128*)p)[2] = _mm_add_epi32(((u128*)p)[2], y);
                ((u128*)p)[3] = _mm_add_epi32(((u128*)p)[3], y);
            }
            for (; p != q; p ++) {
                p[0] += x;
            }
        } else {
            u32 y = 1u;
            for (; ((u64)p & 15u) && p != q; p ++) {
                y *= p[0];
            }
            u32 m = q - p >> 4u;
            u128 y0 = _mm_set1_epi32(1u);
            u128 y1 = _mm_set1_epi32(1u);
            u128 y2 = _mm_set1_epi32(1u);
            u128 y3 = _mm_set1_epi32(1u);
            for (; m --; p += 16u) {
                y0 = _mm_mullo_epi32(y0, ((u128*)p)[0]);
                y1 = _mm_mullo_epi32(y1, ((u128*)p)[1]);
                y2 = _mm_mullo_epi32(y2, ((u128*)p)[2]);
                y3 = _mm_mullo_epi32(y3, ((u128*)p)[3]);
            }
            y0 = _mm_mullo_epi32(y0, y1);
            y2 = _mm_mullo_epi32(y2, y3);
            y0 = _mm_mullo_epi32(y0, y2);
            y *= ((u32*)&y0)[0];
            y *= ((u32*)&y0)[1];
            y *= ((u32*)&y0)[2];
            y *= ((u32*)&y0)[3];
            for (; p != q; p ++) {
                y *= p[0];
            }
            y &= 0xfffff;
            write_u32(y), write_char('\n');
        }
    }
    write_flush();
    fprintf(stderr, "clock=%u\n", (u32)clock());
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

10 10
969575 741825 24903 1047319 450475 256145 1045323 479255 810659 768323
1 5 6 3034
2 1 10
2 1 9
2 1 4
1 3 6 126904
2 5 5
2 9 9
1 7 7 853094
1 4 9 1025178
2 5 8

output:

1045541
1012343
558151
580413
810659
527353

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 1720ms
memory: 4064kb

input:

200000 200000
496015 180543 330721 874799 740427 144379 598057 795949 323465 87657 683935 748203 748665 288301 846003 33033 746029 132621 876629 361899 701297 373189 256151 723161 377571 54947 91151 855991 433965 73347 155081 314317 790527 705555 1035217 298963 604641 203865 230029 802437 720769 843...

output:

746709
564663
426791
840425
762201
413693
881143
534387
189149
257625
60619
958793
250635
869079
383765
151047
272239
146175
46215
914259
617511
698623
381177
932779
792705
785375
1044293
202971
508317
237901
634919
646839
38501
304017
889609
214899
617927
720071
628729
202369
420511
528565
555717
7...

result:

ok 100378 lines

Test #3:

score: 0
Accepted
time: 1727ms
memory: 4084kb

input:

200000 200000
313625 170101 477893 536285 651807 542493 870481 1038171 205037 914869 1020857 263797 349049 146425 49155 634785 620419 520999 216377 365705 284761 874801 450169 521981 238295 791805 292987 339767 765065 1017179 333101 73531 855729 410125 933189 192789 52457 526865 918271 334533 876331...

output:

225575
235385
743949
20373
509445
393347
140689
735475
977073
494895
593783
118129
492359
290607
103169
466197
609397
831915
388819
1031053
461107
492189
790925
208041
397517
1008911
672577
873151
784219
796179
760731
460383
118997
497147
238277
523161
689295
284013
911061
929085
706393
43425
510263...

result:

ok 100374 lines

Test #4:

score: -100
Time Limit Exceeded

input:

200000 200000
739417 442397 798113 1007491 665409 592547 462937 279569 996861 214643 160915 500005 469305 265763 795325 714747 389531 895767 42643 690581 622101 972937 523057 537349 516203 142465 236475 847121 91 207903 662211 217361 719869 627825 604205 672273 850891 1022115 1048509 897035 628451 3...

output:


result: