QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#721011 | #6435. Paimon Segment Tree | wenqizhi | WA | 14ms | 32884kb | C++20 | 5.3kb | 2024-11-07 14:58:08 | 2024-11-07 14:58:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int read()
{
int x = 0; bool f = false; char c = getchar();
while(c < '0' || c > '9') f |= (c == '-'), c = getchar();
while(c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c & 15), c = getchar();
return f ? -x : x;
}
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll mod)
{
ll ans = 1;
while(b)
{
if(b & 1) ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
return ans;
}
const int N = 5e4 + 5;
int n, m, Q;
ll a[N], ans[N];
struct modify{ int l, r, x; }op[N];
struct node{ int id, type, l, r; };
vector<node> q[N];
ll add(ll a, ll b){ return (a + b >= mod) ? (a + b - mod) : (a + b); }
ll del(ll a, ll b){ return (a - b < 0) ? (a - b + mod) : (a - b); }
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
ll sum[N << 2][4];
struct Matrix
{
ll c[4][4];
Matrix(){ memset(c, 0, sizeof(c)); }
Matrix friend operator * (Matrix a, Matrix b)
{
Matrix c;
for(int i = 0; i < 4; ++i)
for(int k = 0; k < 4; ++k)
for(int j = 0; j < 4; ++j)
c.c[i][j] = (c.c[i][j] + a.c[i][k] * b.c[k][j]) % mod;
return c;
}
void clear()
{
for(int i = 0; i < 4; ++i)
for(int j = 0; j < 4; ++j)
c[i][j] = 0;
}
void init()
{
for(int i = 0; i < 4; ++i) c[i][i] = 1;
}
}lazy[N << 2], temp;
void pushup(int k)
{
for(int i = 0; i < 4; ++i)
sum[k][i] = add(sum[ls(k)][i], sum[rs(k)][i]);
}
void mul(int K, Matrix &t)
{
ll a[4] = {0, 0, 0, 0};
for(int k = 0; k < 4; ++k)
for(int j = 0; j < 4; ++j)
a[j] = (a[j] + sum[K][k] * t.c[k][j]) % mod;
for(int i = 0; i < 4; ++i) sum[K][i] = a[i];
}
void pushdown(int k)
{
mul(ls(k), lazy[k]), mul(rs(k), lazy[k]);
lazy[ls(k)] = lazy[ls(k)] * lazy[k];
lazy[rs(k)] = lazy[rs(k)] * lazy[k];
lazy[k].clear(), lazy[k].init();
}
void build(int k, int l, int r)
{
// printf("k = %d, l = %d, r = %d\n", k, l, r);
lazy[k].init();
if(l == r)
{
sum[k][0] = 1;
sum[k][1] = a[l];
sum[k][2] = a[l] * a[l] % mod;
sum[k][3] = sum[k][2];
return ;
}
int mid = (l + r) >> 1;
build(ls(k), l, mid), build(rs(k), mid + 1, r);
pushup(k);
}
ll query(int k, int l, int r, int L, int R)
{
if(L <= l && r <= R) return sum[k][3];
pushdown(k);
int mid = (l + r) >> 1;
if(R <= mid) return query(ls(k), l, mid, L, R);
if(L > mid) return query(rs(k), mid + 1, r, L, R);
return add(query(ls(k), l, mid, L, R), query(rs(k), mid + 1, r, L, R));
}
void update(int k, int l, int r, int L, int R)
{
if(L <= l && r <= R)
{
mul(k, temp);
lazy[k] = lazy[k] * temp;
return ;
}
pushdown(k);
int mid = (l + r) >> 1;
if(L <= mid) update(ls(k), l, mid, L, R);
if(R > mid) update(rs(k), mid + 1, r, L, R);
pushup(k);
}
void down(int k, int l, int r)
{
if(l == r) return ;
pushdown(k);
int mid = (l + r) >> 1;
down(ls(k), l, mid), down(rs(k), mid + 1, r);
}
int main()
{
n = read(), m = read(), Q = read();
for(int i = 1; i <= n; ++i) a[i] = read();
build(1, 1, n);
for(int i = 1; i <= m; ++i)
{
op[i].l = read();
op[i].r = read();
op[i].x = read();
}
for(int i = 1; i <= Q; ++i)
{
int l = read(), r = read(), x = read(), y = read();
if(x >= 1) q[x - 1].emplace_back((node){i, -1, l, r});
q[y].emplace_back((node){i, 1, l, r});
}
// printf("t = 0\n");
for(auto [id, type, l, r] : q[0])
{
// printf("query(%d, %d) = %lld\n", l, r, query(1, 1, n, l, r));
ans[id] = (ans[id] + query(1, 1, n, l, r) * type + mod) % mod;
}
for(int t = 1; t <= m; ++t)
{
if(op[t].l > 1)
{
temp.clear();
temp.c[0][0] = temp.c[1][1] = temp.c[2][2] = temp.c[3][3] = temp.c[2][3] = 1;
update(1, 1, n, 1, op[t].l - 1);
}
if(op[t].r < n)
{
temp.clear();
temp.c[0][0] = temp.c[1][1] = temp.c[2][2] = temp.c[3][3] = temp.c[2][3] = 1;
update(1, 1, n, op[t].r + 1, n);
}
temp.clear();
temp.c[0][0] = temp.c[1][1] = temp.c[2][2] = temp.c[3][3] = temp.c[2][3] = 1;
temp.c[0][1] = op[t].x , temp.c[1][2] = temp.c[1][3] = add(op[t].x , op[t].x );
temp.c[0][2] = temp.c[0][3] = 1ll * op[t].x * op[t].x % mod;
update(1, 1, n, op[t].l , op[t].r );
// printf("t = %d\n", t);
// printf("query(2, 2) = %lld\n", query(1, 1, n, 2, 2));
// for(int i = 0; i < 4; ++i) printf("%d ", sum[5][i]);
// printf("\n");
// down(1, 1, n);
// for(int i = 0; i < 4; ++i)
// {
// for(int j = 0; j < 4; )
// }
for(auto [id, type, l, r] : q[t])
{
// printf("query(%d, %d) = %lld\n", l, r, query(1, 1, n, l, r));
ans[id] = (ans[id] + query(1, 1, n, l, r) * type + mod) % mod;
}
}
for(int i = 1; i <= Q; ++i) printf("%lld\n", (ans[i] % mod + mod) % mod);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 29704kb
input:
3 1 1 8 1 6 2 3 2 2 2 0 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 6ms
memory: 32576kb
input:
4 3 3 2 3 2 2 1 1 6 1 3 3 1 3 6 2 2 2 3 1 4 1 3 4 4 2 3
output:
180 825 8
result:
ok 3 number(s): "180 825 8"
Test #3:
score: 0
Accepted
time: 3ms
memory: 32384kb
input:
100 107 180 -280960553 266308104 -997644864 856103777 592874377 674379235 -946339772 641750362 642418716 -360811715 -555543246 206614021 358239245 349842656 983198973 807518446 -66612455 -980932737 109826132 -109676067 51226145 452115561 -42729559 -950621304 -87009773 714026474 375317493 693260053 -...
output:
400489222 480617351 531108525 254983761 446689548 764223236 142229431 307405789 39817281 66225912 247029353 46506707 529135498 578008236 201809860 674078444 746060191 171471121 722471473 657196163 861551838 606551808 360903956 401221326 767571915 669762004 163759234 141144218 579174939 276557168 518...
result:
ok 180 numbers
Test #4:
score: 0
Accepted
time: 3ms
memory: 31204kb
input:
295 269 129 -210918287 343352194 936488821 -682920910 944685019 677819690 -913857474 643356008 215752838 -582778677 735744580 307969642 807954422 388654459 761031712 -978166251 65058102 236039317 -205619898 -79984863 977152006 79198370 -999053192 -933631858 -776338105 -988909566 -427172257 -83477275...
output:
618251287 899907228 531858556 882858895 725455126 938410366 816431580 6908535 24554323 39964258 545169468 118739750 324108277 57969570 909045869 771733081 78663884 765348479 855417630 840946863 849560917 792963883 68199493 607258525 976267825 554521243 921526613 189188489 544501166 169313970 7657692...
result:
ok 129 numbers
Test #5:
score: 0
Accepted
time: 2ms
memory: 31308kb
input:
290 130 153 467014672 -187494410 -834410250 -221945583 -113569812 976227414 823657567 644961655 -718120549 900287103 634923088 999259803 -742330414 114542837 -69026244 941181808 998903438 650836591 381792036 -50293659 -391889416 -588686091 44623189 -916642412 -368524388 505979642 770338007 734336505...
output:
205306195 913174634 627098553 583511289 53628555 776119748 741459303 361721232 792181766 998349032 63183274 449140540 772865125 869222155 83821401 342565107 772194112 208578315 473166159 924882996 534863573 359442652 252396430 259427632 357792582 605715971 225467777 31224502 410770535 77000480 73685...
result:
ok 153 numbers
Test #6:
score: 0
Accepted
time: 7ms
memory: 30948kb
input:
184 292 178 -560085111 986691728 196865471 -958795491 238240831 979667868 -848892877 351600031 -849819158 973287410 -73789099 492724730 509559542 743289180 3773764 -844502889 -869426018 770666596 66346005 -20602454 534036445 135538767 -911700444 -604685696 942147293 -607021858 -32151743 -793696299 -...
output:
858202984 433975321 69198683 98775914 749936095 716134874 281147731 186709890 903234421 920600352 323335030 69435264 896305275 257633690 55255202 182091822 935500760 726305425 381037995 804018605 478673738 484297808 286861521 10149069 594778768 547188580 540808257 427373166 853802061 768386487 90138...
result:
ok 178 numbers
Test #7:
score: 0
Accepted
time: 4ms
memory: 31192kb
input:
179 152 127 117847849 -936264195 130999142 -202852895 885018743 -721924420 -816410579 353205678 -686550496 751320448 -174610592 889047621 959274719 469177558 -826284192 779877900 64419317 -814536143 -249100025 -793086029 262137073 -237378424 739866630 -587696250 -42148309 887867350 -834641493 -26761...
output:
505009166 348176298 768846383 639656852 767297876 334028836 672141959 865320262 32468111 824990615 935878450 39788029 776229057 745398975 622480518 927354339 667485118 767183633 797234162 637335006 725843572 397083849 891541202 474690368 807830014 546532554 370859947 512952106 797356109 977040750 56...
result:
ok 127 numbers
Test #8:
score: 0
Accepted
time: 5ms
memory: 30980kb
input:
173 215 251 482857384 237921943 65132814 -644735533 -173236088 -423516696 921104462 -742330725 886783639 -862755834 -883322779 677479818 -591010117 -902076112 951548559 994193216 -706768090 697403181 338311909 -763394825 -811937079 799769858 -216457003 -570706804 660632678 -520101420 657836040 -4576...
output:
532409264 425334301 297106918 497679015 766180735 997240773 876619970 775627119 369095265 141725042 860632646 806561262 693330436 844811627 533129631 666137230 797776768 349015941 304013406 366877046 285656333 796617951 263787451 188404775 795402622 368862072 922591321 853125733 448636483 903008737 ...
result:
ok 251 numbers
Test #9:
score: 0
Accepted
time: 7ms
memory: 30076kb
input:
168 151 100 -544242399 314966033 -903591478 -478727476 178574554 -420076241 -751445982 -740725078 -47089749 915277216 112997778 778835439 -141294940 -863264310 121490604 -791491481 834967940 -887799557 22865879 971329122 -475945758 426852667 827219378 -553717358 -28695654 71929823 758204255 14314631...
output:
352187626 704247599 53684196 147547097 652201927 257200097 626135496 49775525 672820311 189599120 469216129 487715787 155787875 856115710 757497826 561926086 567295451 568260936 378849834 906105482 480823862 527730971 133376678 862463926 443893047 318620602 549415798 799707998 458453406 462381509 43...
result:
ok 100 numbers
Test #10:
score: 0
Accepted
time: 4ms
memory: 30896kb
input:
163 213 224 133690560 -215880572 -674490536 -625642844 825352466 -121668517 -718963684 -739119431 -178788357 693310253 307143555 567267636 308420237 862624082 -100676658 -872143435 63780533 -767969553 -587547422 -96121722 155012833 53935476 773753709 560414138 987008757 -433180982 -44285495 48628183...
output:
747432440 517227949 996821749 805271519 840593989 22089777 153536567 999462554 483313583 174809962 671096506 911407220 301225235 350791783 414302958 610922065 348064356 221620487 622546838 251737080 930284090 787053181 512448105 483900137 418446165 774811006 614925836 789232720 98746705 671256184 88...
result:
ok 224 numbers
Test #11:
score: 0
Accepted
time: 4ms
memory: 31068kb
input:
258 174 173 -893409223 958305567 -740356864 -459634788 -527869635 176739208 -981448656 967518958 -15519695 176376021 -991503172 668623257 758135414 -508629589 -930734614 -657828118 -707406874 743969771 -902993452 -66430518 -919061319 -613948985 -772504464 577403584 -310210269 158850261 -846775245 55...
output:
763779848 971203287 417629333 128055735 17327247 15630176 25359233 62738585 361956876 281789376 957004306 7982723 694276684 450550861 225480663 650754963 57977660 889194726 638963520 880818703 608956290 276560765 718925350 342938575 243384787 865317875 569251525 302758871 232054208 811410731 1124094...
result:
ok 173 numbers
Test #12:
score: 0
Accepted
time: 3ms
memory: 32884kb
input:
224 261 183 321076468 14144917 -964309122 -998152041 -233777241 498830290 -124389333 152924562 100565362 -951633735 -51153541 -539047258 -158691246 266759044 -656520429 -577382886 -383476274 -274905450 -161914533 -572427748 644517420 376447356 -227879896 -972623510 702539156 -675224598 698346506 -17...
output:
322262446 309629779 753522996 746794296 331484522 808430979 727359918 533145896 642265099 611737090 791371384 936246806 480013565 761553227 859970290 114739196 147749092 992690312 222043170 425264912 61368448 532877858 131993381 347759625 310385807 693085135 594668938 342481048 673051834 663459641 1...
result:
ok 183 numbers
Test #13:
score: 0
Accepted
time: 7ms
memory: 29976kb
input:
500 500 500 702413239 -895672661 513406482 -706023315 -811668957 -735208181 -537176715 118033401 207303475 203060235 -140437061 -31133246 -878633428 945167015 -142724367 291023931 895505386 218454358 -658034840 845336331 139891825 -182393293 -837703814 -429556732 -291437105 -281345565 -660666794 132...
output:
799094138 146472194 58171908 40775791 547185279 571631473 320570241 279864315 784754669 36384176 647854975 369168115 86332530 547176983 240323948 240924775 72654152 69035557 647102037 39065205 809733534 122261401 419058965 996509642 840422954 505500073 254560823 567513427 197957750 174710109 8980857...
result:
ok 500 numbers
Test #14:
score: 0
Accepted
time: 7ms
memory: 31276kb
input:
500 500 500 -124873923 -862644826 -949273940 266876915 -439657598 -801074509 -979059352 -940221430 505711199 -59424737 -138831414 -965006634 899399622 -860687221 -649259440 740739108 621393765 291254366 -443719524 -220818346 -348168865 -497839324 -513045340 201401859 -959321566 762330816 -643677348 ...
output:
726058600 157394298 6026295 626157799 473455503 836929915 65432281 223447620 258103506 201786082 245837249 839381477 776736180 495914531 234139152 826978202 609481390 609186653 448424325 37801505 772356936 176131960 94645367 507234205 491293083 51500902 336742281 8572500 581656090 337181638 19093229...
result:
ok 500 numbers
Test #15:
score: -100
Wrong Answer
time: 14ms
memory: 32656kb
input:
500 500 500 -952161085 875415752 980154970 336919180 734528541 525168482 -813051296 -293443518 804118924 -26942438 157741502 608327501 382465389 135633335 -252936549 -809545728 660205567 -538803590 -229404208 -89147789 -228338860 89572610 419503829 224469756 -235096708 -488960087 -626687902 -2683037...
output:
948178708 63043518 412562474 979471847 632004126 197149770 44765001 333070147 209208490 245340835 327984181 86381120 108549140 206693435 696566524 692690063 761978712 63394241 115659288 133306357 949561112 412838504 951662013 614320278 450808891 653747562 528431330 653894325 459172133 26721646 92240...
result:
wrong answer 93rd numbers differ - expected: '34841094', found: '617185102'