QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376479 | #3720. Longest Increasing Subsequence | pppppp | AC ✓ | 637ms | 4244kb | C++17 | 1.5kb | 2024-04-04 10:41:02 | 2024-04-04 10:41:02 |
Judging History
answer
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<math.h>
#include<set>
//#define int long long
#define INF 0x3f3f3f3f
//#define unint unsigned long long
using namespace std;
#define PII pair<int,int>
const int N=5e3+10;
int n,a[N],k;
int b[N],f[N],cnt[N],cnt2[N];
int sum=0;
vector<int> V[N];
int ans=0;
void dfs(int x)
{
// memset(cnt2,0,sizeof cnt2);
int l=V[x].size();
for(int j=0;j<l;j++)
{
int xx=V[x][j];
cnt2[xx]++;
if(cnt2[xx]==cnt[xx])
{
ans=ans^(f[xx]*f[xx])^((f[xx]-1)*(f[xx]-1));
dfs(xx);
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
while(cin>>n)
{
memset(cnt,0,sizeof cnt);
int len=0;
sum=0;
for(int i=1;i<=n;i++)
{
b[i]=0;
cin>>a[i];
V[i].clear();
if(a[i]>b[len])
{
b[++len]=a[i];
f[i]=len;
}
else
{
int j=lower_bound(b+1,b+len+1,a[i])-b;
b[j]=a[i];
f[i]=j;
}
sum^=(f[i]*f[i]);
for(int j=1;j<i;j++)
{
if(a[j]<a[i])
{
if(f[i]==(f[j]+1))
{
V[j].push_back(i);//j的后续 i可以由j得到
cnt[i]++; //可以得到i的方式有几种
}
}
}
}
ans=0;
for(int i=1;i<=n;i++)
{
ans=sum^(f[i]*f[i]);
memset(cnt2,0,sizeof(cnt2));
dfs(i);//遍历i可能会影响到的
cout<<ans<<" ";
}
cout<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 637ms
memory: 4244kb
input:
5000 2 10 12 15 16 19 20 21 23 25 26 27 28 31 32 35 36 38 39 41 43 46 47 48 50 53 54 58 59 60 61 62 63 66 67 68 69 70 72 74 76 78 84 87 88 90 91 92 93 94 95 97 98 99 100 102 103 105 106 107 108 109 110 111 112 113 114 116 117 118 119 120 121 123 125 126 129 130 131 133 137 138 141 143 144 146 148 15...
output:
7547072 7547129 7547129 7547129 7547129 7547089 7547089 7547089 7547125 7547125 7547125 7547125 7547125 7547125 7547125 7547125 7547125 7547024 7547024 7546985 7546944 7547880 7547880 7547880 7547865 7547761 7547761 7547688 7547688 7547688 7547688 7547688 7547688 7547808 7547808 7547808 7547808 7547...
result:
ok 50000 numbers