QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200785 | #4477. Pandaemonium Asphodelos: The First Circle (Savage) | yiyiyi | AC ✓ | 572ms | 26632kb | C++17 | 6.0kb | 2023-10-04 19:58:21 | 2023-10-04 19:58:21 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(int i=(s);i>=(t);i--)
using namespace std;
int ci(){
int x; scanf("%d",&x); return x;
}
enum{N=200023};
/*
struct dt{ ll sum; };
dt NIL = (dt){0};
dt operator+(const dt&a,const dt&b){
return (dt){a.sum+b.sum};
}
class SEG{
private:
struct node{
node*c[2];
dt x,tag;
#define lch c[0]
#define rch c[1]
void update(){
x = lch->x + rch->x;
}
}d[N*42];
int tot_d;
void func(dt& x, int l, int r, dt k){
x.sum += (r-l+1)*k.sum;
}
void downdate(node*e, int l,int r){
int mid = (l+r)/2;
if( e->lch==d ) e->lch = &(d[++tot_d]=*d);
if( e->rch==d ) e->rch = &(d[++tot_d]=*d);
func(e->lch->x, l,mid, e->tag);
func(e->lch->tag, 1,1, e->tag);
func(e->rch->x, mid+1,r, e->tag);
func(e->rch->tag, 1,1, e->tag);
e->tag = NIL;
}
void add(node*&e,int l,int r,int ql,int qr,dt x){
if( e==d ) e = &(d[++tot_d]=*d);
if( ql<=l && r<=qr ) return func(e->x, l,r, x), func(e->tag,1,1,x), void();
downdate(e,l,r);
int mid = (l+r)/2;
( ql<=mid ? add(e->lch, l,mid ,ql,qr,x) : void());
( mid< qr ? add(e->rch,mid+1,r,ql,qr,x) : void());
e->update();
}
dt query(node*e,int l,int r,int ql,int qr){
if( e==d ) return NIL;
if( ql<=l && r<=qr ) return e->x;
int mid = (l+r)/2;
downdate(e,l,r);
return ( ql<=mid ? query(e->lch, l,mid ,ql,qr) : NIL)
+( mid< qr ? query(e->rch,mid+1,r,ql,qr) : NIL);
}
int n;
node*ver[5];
public:
void init(int tot_ver,int n0){
*d = (node){d,d,NIL,NIL};
tot_d = 0;
n = n0;
fill(ver,ver+tot_ver+1,(node*)d);
}
void add(int x,int l,int r,dt y){
add(ver[x],1,n,l,r,y);
}
dt query(int x,int l,int r){
return query(ver[x],1,n,l,r);
}
}seg;
*/
struct dt{ ll sum; };
dt NIL = (dt){0};
dt operator+(const dt&a,const dt&b){
return (dt){a.sum+b.sum};
}
class SEG{
private:
struct node{
node*c[2];
dt x;
#define lch c[0]
#define rch c[1]
void update(){
x = lch->x + rch->x;
}
}d[N*45];
int tot_d;
void add(node*&e,int l,int r,int ql,int qr,dt x){
if( e==d ) e = &(d[++tot_d]=*d);
if( ql<=l && r<=qr ) return e->x = e->x+x, void();
int mid = (l+r)/2;
( ql<=mid ? add(e->lch, l,mid ,ql,qr,x) : void());
( mid< qr ? add(e->rch,mid+1,r,ql,qr,x) : void());
e->update();
}
dt query(node*e,int l,int r,int ql,int qr){
if( e==d ) return NIL;
if( ql<=l && r<=qr ) return e->x;
int mid = (l+r)/2;
return ( ql<=mid ? query(e->lch, l,mid ,ql,qr) : NIL)
+( mid< qr ? query(e->rch,mid+1,r,ql,qr) : NIL);
}
node*ver[5];
int n;
public:
void init(int tot_ver,int n0){
*d = (node){d,d,NIL};
tot_d = 0;
n = n0;
fill(ver,ver+tot_ver+1,(node*)d);
}
void add(int x,int p,dt y){
if( p>n ) return;
if( p<1 ) return;
add(ver[x],1,n,p,p,y);
}
dt query(int x,int l,int r){
return query(ver[x],1,n,l,r);
}
}seg;
ll c[N];
#define qwq first
#define awa second
using range = pair<int,int>;
using CH = map<range,int>;
class chtholly{
private:
CH m;
CH::iterator split(int p){
CH::iterator it = m.lower_bound(range(p,0));
if( it->qwq.qwq==p ) return it;
it--;
int l = it->qwq.qwq, r = it->qwq.awa, x=it->awa;
m.erase(it);
m[range(l,p-1)] = x;
m[range(p,r)] = x;
return m.find(range(p,r));
}
public:
void init(int n){
m.clear();
m[range(0,0)] = -1;
m[range(1,n)] = 1;
m[range(n+1,n)] = -1;
}
void assign(int l0,int r0, int x0){
//printf("line %d: [%d %d] %d\n", __LINE__, l,r,x);
CH::iterator R = split(r0+1), L = split(l0);
for(auto it=L; it!=R; it++){
int l = it->qwq.qwq, r = it->qwq.awa, x=it->awa;
//printf("line %d: add %d %d %d\n", __LINE__, l,r,c[x]);
seg.add(1,l,(dt){c[x]});
seg.add(1,r+1,(dt){-c[x]});
}
m.erase(L,R);
//printf("line %d:\n", __LINE__);
m[range(l0,r0)] = x0;
}
void expand(int x, int y){
CH::iterator it = m.lower_bound(range(x,0));
if( it->qwq.qwq==x ) ;
else it--;
int colx = it->awa;
it = m.lower_bound(range(y,0));
if( it->qwq.qwq==y ) ;
else it--;
int col = it->awa;
//printf("line %d: col %d %d\n", __LINE__, col, colx);
auto L = it;
while( L->awa == col ) L--;
L++;
int l0 = L->qwq.qwq, r0 = it->qwq.qwq-1;
//printf("line %d: %d %d %d\n", __LINE__, l,r,colx);
for(it=L; it->awa==col; it++){
int l = it->qwq.qwq, r = it->qwq.awa;
//printf("line %d: lr %d %d %d + %lld\n", __LINE__, l,r,x, c[col]-c[colx]);
seg.add(1,l,(dt){c[col]-c[colx]});
seg.add(1,r+1,(dt){-c[col]+c[colx]});
}
l0 = L->qwq.qwq, r0 = it->qwq.qwq-1;
//printf("line %d: %d %d %d\n", __LINE__, l,r,colx);
m.erase(L,it);
m[range(l0,r0)] = colx;
}
int query(int x){
auto it = m.lower_bound(range(x,0));
if( it->qwq.qwq==x ) ;
else it--;
return it->awa;
}
}ch;
#undef qwq
#undef awa
signed main(){
//printf("line %d: %lld\n", __LINE__, sizeof seg);
int T = ci();
while( T-- ){
int n = ci();
int q = ci();
ch.init(n);
seg.init(2,n);
int tot = 1;
c[1] = 0;
int last = 0;
while( q-- ){
int opt = ci();
//printf("line %d: opt %d\n", __LINE__, opt);
if( opt==1 ){
int x = ci(), d = ci();
x = ((x-1)^last)%n+1;
d = ((d-1)^last)%((n-1)/2)+1;
int l = max(1,x-d), r = l+2*d;
if (r > n) l = n - 2 * d, r = n;
c[++tot] = 0;
ch.assign(l,r, tot);
}else if( opt==2 ){
int x = ci(), y = ci();
x = ((x-1)^last)%n+1;
y = ((y-1)^last)%n+1;
ch.expand(x,y);
}else if( opt==3 ){
int x = ci(), v = ci();
x = ((x-1)^last)%n+1;
c[ch.query(x)] += v;
// printf("line %d:\n", __LINE__);
//rep(i,1,tot) printf("%lld ", c[i]); puts("");
}else if( opt==4 ){
int x = ci();
x = ((x-1)^last)%n+1;
//printf("line %d: 4 %d\n", __LINE__, x);
ll ans = seg.query(1,1,x).sum + c[ch.query(x)];
//printf("line %d: %lld %lld\n", __LINE__, seg.query(1,x,x).sum , c[ch.query(x)]);
printf("%lld\n", ans);
last=ans&1073741823;
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 572ms
memory: 26632kb
input:
16 16 12 3 10 16 4 2 1 1 6 1 5 6 1 9 7 1 15 7 2 2 10 2 2 13 3 1 16 4 16 4 9 4 4 100 10 3 52 336470888 2 46 95 4 98 3 3 971207868 2 6 18 2 27 38 3 68 717268783 4 69 4 30 2 2 54 100000000 100 3 23264237 374288891 1 51244358 31960832 3 66089174 543529670 3 19728747 580543238 3 68188689 490702144 1 3862...
output:
16 32 32 16 336470888 2024947539 2024947539 1989063943 1989063943 3947292200 2332517148 3947292200 2332517148 2332517148 2173902728 3154913316 3154913316 7792501902 5025837134 5196716262 7081781397 5196716262 6177726850 7031735014 7081781397 7081781397 7589349584 10153736164 9944646904 12358787010 9...
result:
ok 166382 lines