QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#537070 | #3720. Longest Increasing Subsequence | sudoku | AC ✓ | 269ms | 1616kb | C++17 | 1.6kb | 2024-08-29 19:48:02 | 2024-08-29 19:48:03 |
Judging History
answer
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long int
int a[5500];
int dp[5500];
int f[5500];
int s[5500];
int n;
void init()
{
memset(dp,0,sizeof(dp));
memset(f,0,sizeof(f));
memset(s,0,sizeof(s));
memset(a,0,sizeof(a));
int c=0;
for(int i=1;i<=n;i++)
{
int t;
scanf("%d",&t);
a[i]=t;
if(i==1)f[++c]=t,dp[i]=c;
else
{
if(t>f[c])f[++c]=t,dp[i]=c;
else
{
int pos=lower_bound(f+1,f+c,t)-f;//二分找到数组中比t大的第一个元素的的地址。
f[pos]=t;
dp[i]=pos;
}
}
}
}
int main()
{
while(~scanf("%d",&n))
{
init();
for(int i=1;i<=n;i++)
{
memset(s,0x7f,sizeof(s));
s[0]=0;
ll ans=0;
for(int j=1;j<=i-1;j++)
{
s[dp[j]]=min(s[dp[j]],a[j]);
ans^=((ll)dp[j]*(ll)dp[j]);
}
for(int j=i+1;j<=n;j++)
{
if(a[j]>s[dp[j]-1])
{
s[dp[j]]=min(s[dp[j]],a[j]);
ans^=((ll)dp[j]*(ll)dp[j]);
}
else
{
s[dp[j]-1]=min(s[dp[j]-1],a[j]);
ans^=((ll)(dp[j]-1)*(ll)(dp[j]-1));
}
}
if(i!=1)printf(" ");
printf("%lld",ans);
}
printf("\n");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 269ms
memory: 1616kb
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