QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#805837 | #2204. Border | Rong7 | AC ✓ | 726ms | 497052kb | C++20 | 2.4kb | 2024-12-08 18:54:29 | 2024-12-08 18:54:30 |
Judging History
answer
// Go in my style.
// Not afraid to dark.
#include <bits/stdc++.h>
using namespace std;
clock_t sttime;
#define STCLOCK sttime = clock ();
#define TIMENOW fprintf (stderr, "\nNOW TIME COSSEMED: %0.4lf\n", 1.0 * (clock () - sttime) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))
namespace io {
int read_pos, read_dt; char read_char;
inline int read (int &p = read_pos){
p = 0, read_dt = 1; read_char = getchar ();
while (! isdigit (read_char)){
if (read_char == '-')
read_dt = - 1;
read_char = getchar ();
}
while (isdigit (read_char)){
p = (p << 1) + (p << 3) + read_char - 48;
read_char = getchar ();
}
return p = p * read_dt;
}
int write_sta[65], write_top;
inline void write (long long x){
if (x < 0)
putchar ('-'), x = - x;
write_top = 0;
do
write_sta[write_top ++] = x % 10, x /= 10;
while (x);
while (write_top)
putchar (write_sta[-- write_top] + 48);
}
}
const int N = 1e6;
int n, sed, s[N + 5], nex[55], pos[55];
int tot;
struct trie {
int to[2], cnt;
char v;
} tr[N * 40 + 5];
inline int geto (int i, int j){
if (! tr[i].to[j])
tr[i].to[j] = ++ tot, tr[tot].v = tr[i].v + 1;
tr[tot].cnt = tr[tot].to[0] = tr[tot].to[1] = 0;
return tr[i].to[j];
}
inline void ins (int *s, int n){
static int nex[55], pos[55];
nex[1] = nex[0] = 0;
pos[1] = geto (0, s[1]);
++ tr[pos[1]].cnt;
for (int i = 2;i <= n;++ i){
pos[i] = geto (pos[i - 1], s[i]);
nex[i] = nex[i - 1];
while (nex[i] > 0 && s[nex[i] + 1] != s[i]) nex[i] = nex[nex[i]];
if (s[nex[i] + 1] == s[i]) ++ nex[i];
tr[pos[i]].v = i - nex[i];
++ tr[pos[i]].cnt;
// printf ("(%d %d)", nex[i], tr[pos[i]].v);
}
// puts ("");
}
signed main (){
STCLOCK
io::read (n), io::read (sed);
for (int i = 1;i <= n;++ i){
sed = (13331ll * sed + 23333) % 1000000007;
s[i] = sed & 1;
// printf ("%d", s[i]);
}
// puts ("");
tr[0].to[0] = tr[0].to[1] = tr[0].cnt = tr[0].v = 0;
for (int i = 1;i <= n;++ i) ins (s + i - 1, min (50, n - i + 1));
long long ans = 0;
for (int i = 0;i <= tot;++ i) ans += 1ll * tr[i].cnt * (tr[i].cnt - 1) / 2 * tr[i].v;
io::write (ans), putchar ('\n');
TIMENOW
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 1ms
memory: 6084kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 6096kb
Test #3:
score: 0
Accepted
time: 1ms
memory: 6100kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 6328kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 6392kb
Test #6:
score: 0
Accepted
time: 56ms
memory: 61104kb
Test #7:
score: 0
Accepted
time: 52ms
memory: 61136kb
Test #8:
score: 0
Accepted
time: 59ms
memory: 63808kb
Test #9:
score: 0
Accepted
time: 67ms
memory: 61536kb
Test #10:
score: 0
Accepted
time: 59ms
memory: 61324kb
Test #11:
score: 0
Accepted
time: 48ms
memory: 63912kb
Test #12:
score: 0
Accepted
time: 59ms
memory: 60332kb
Test #13:
score: 0
Accepted
time: 726ms
memory: 496172kb
Test #14:
score: 0
Accepted
time: 697ms
memory: 497044kb
Test #15:
score: 0
Accepted
time: 707ms
memory: 495204kb
Test #16:
score: 0
Accepted
time: 693ms
memory: 495128kb
Test #17:
score: 0
Accepted
time: 696ms
memory: 495364kb
Test #18:
score: 0
Accepted
time: 707ms
memory: 495868kb
Test #19:
score: 0
Accepted
time: 698ms
memory: 496640kb
Test #20:
score: 0
Accepted
time: 717ms
memory: 495180kb
Test #21:
score: 0
Accepted
time: 696ms
memory: 495044kb
Test #22:
score: 0
Accepted
time: 722ms
memory: 496364kb
Test #23:
score: 0
Accepted
time: 682ms
memory: 496200kb
Test #24:
score: 0
Accepted
time: 694ms
memory: 496616kb
Test #25:
score: 0
Accepted
time: 701ms
memory: 495524kb
Test #26:
score: 0
Accepted
time: 682ms
memory: 497052kb
Test #27:
score: 0
Accepted
time: 692ms
memory: 496576kb
Test #28:
score: 0
Accepted
time: 697ms
memory: 496120kb
Test #29:
score: 0
Accepted
time: 703ms
memory: 496720kb
Test #30:
score: 0
Accepted
time: 715ms
memory: 495272kb
Test #31:
score: 0
Accepted
time: 717ms
memory: 495500kb
Test #32:
score: 0
Accepted
time: 672ms
memory: 496256kb
Test #33:
score: 0
Accepted
time: 714ms
memory: 496944kb
Test #34:
score: 0
Accepted
time: 716ms
memory: 495744kb
Test #35:
score: 0
Accepted
time: 698ms
memory: 495160kb
Test #36:
score: 0
Accepted
time: 708ms
memory: 496732kb
Test #37:
score: 0
Accepted
time: 694ms
memory: 495576kb
Test #38:
score: 0
Accepted
time: 685ms
memory: 495392kb
Test #39:
score: 0
Accepted
time: 700ms
memory: 495644kb
Test #40:
score: 0
Accepted
time: 663ms
memory: 496648kb
Test #41:
score: 0
Accepted
time: 723ms
memory: 496872kb
Test #42:
score: 0
Accepted
time: 679ms
memory: 495068kb
Test #43:
score: 0
Accepted
time: 684ms
memory: 495256kb
Test #44:
score: 0
Accepted
time: 712ms
memory: 495992kb
Test #45:
score: 0
Accepted
time: 705ms
memory: 495780kb
Test #46:
score: 0
Accepted
time: 708ms
memory: 496116kb
Test #47:
score: 0
Accepted
time: 715ms
memory: 495508kb
Test #48:
score: 0
Accepted
time: 712ms
memory: 495856kb
Test #49:
score: 0
Accepted
time: 708ms
memory: 495204kb
Test #50:
score: 0
Accepted
time: 705ms
memory: 496544kb
Test #51:
score: 0
Accepted
time: 718ms
memory: 495876kb
Test #52:
score: 0
Accepted
time: 710ms
memory: 497032kb
Test #53:
score: 0
Accepted
time: 710ms
memory: 495104kb
Test #54:
score: 0
Accepted
time: 700ms
memory: 496140kb
Test #55:
score: 0
Accepted
time: 683ms
memory: 495680kb