Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
42642 ZZQ [CSP-J2021]插入排序 C++ 通过 100 97 MS 4904 KB 1270 2022-01-26 10:29:54

Tests(25/25):


#include <bits/stdc++.h> using namespace std; long long a[8005]; struct node { int son[2], vis; } t[5000005]; int pos=1; inline int Read() { int x=0; char c=getchar(); for(; c<'0' || c>'9'; c=getchar()); for(; c<='9' && c>='0'; c=getchar()) x=(x<<3)+(x<<1)+(c^48); return x; } void Add(long long x) { int p=1; ++t[p].vis; for (int i=63; i>=0; --i) { bool b=(x>>i) & 1; if (!t[p].son[b]) t[p].son[b]=++pos; p = t[p].son[b]; ++t[p].vis; } } void Del(long long x) { int p=1; --t[p].vis; for (int i=63; i>=0; --i) { p=t[p].son[(x>>i) & 1]; if (p) --t[p].vis; } } int Query(long long x) { int ans=0, p=1; for (int i=63; i>=0; --i) { bool b=(x>>i) & 1; if (b) ans+=t[t[p].son[0]].vis; p=t[p].son[b]; if (!p) return ans; } return ans; } int main() { int n=Read(), q=Read(); for (int i=1; i<=n; ++i) { a[i]=Read(); Add(1ll*(a[i]*n+i)); } for (int i=1,opt,x,v; i<=q; ++i) { opt=Read(),x=Read(); if (opt==1) { v=Read(); Del(1ll*(a[x]*n+x)); a[x]=v; Add(1ll*(a[x]*n+x)); } else printf("%d\n",Query(1ll*(a[x]*n+x)+1)); } return 0; }


测评信息: