QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647245#8354. T2songziyan0 4ms28680kbC++141.3kb2024-10-17 12:59:202024-10-17 12:59:21

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 12:59:21]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:28680kb
  • [2024-10-17 12:59:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
char buf[1<<22],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1==p2)?0:*p1++)
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch))f=(ch=='-')?-1:1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x*f;
}
const int N=2e6+5;
int n,K,q,B,op[5005],x[5005],ans[5005],f[N],g[N],p[N],v[N],t[N],vis[N],perm[N];
void add1(int i){for(int j=K;j>=t[i];j--)f[j]=max(f[j],f[j-t[i]]+v[i]);}
void add2(int i){for(int j=K/p[i];j>=v[i];j--)g[j]=min(g[j],g[j-v[i]]+t[i]);}
void trans(int i){if(p[i]<=B)add1(i);else add2(i);}
signed main(){
    mt19937_64 randnum(time(0));
    n=read();q=read();K=read();B=sqrt(n+q);
    fill(perm+1,perm+1+n,1);shuffle(perm+1,perm+1+n,randnum);
    for(int i=1;i<=n;i++)p[i]=read(),v[i]=read(),t[i]=p[i]*v[i];
    for(int i=1;i<=q;i++){
        op[i]=read(),x[i]=read();
        if(op[i]==1)vis[x[i]]=1;
    }
    memset(g,0x3f,sizeof(g));g[0]=0;
    for(int i=1;i<=n;i++)if(!vis[p[i]])trans(p[i]);
    for(int i=q;i>=1;i--)
        if(op[i]==1)trans(x[i]);
        else{int &res=ans[i];for(int j=x[i]/B;j>=0;j--)if(x[i]>=g[j])res=max(res,f[x[i]-g[j]]+j);}
    for(int i=1;i<=q;i++)if(op[i]==2)printf("%lld\n",ans[i]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 28680kb

input:

3205 5000 5000
1 1
2 1
3 1
7 1
8 1
9 1
10 1
11 1
12 2
13 1
14 2
16 1
17 2
20 3
22 1
24 1
26 2
27 1
30 1
32 2
33 1
34 1
41 1
44 2
49 2
51 1
54 2
58 2
61 2
65 2
66 1
68 2
70 1
71 2
72 2
74 8
75 3
76 5
77 1
78 7
79 5
80 5
81 1
82 2
84 1
86 6
87 6
88 3
89 9
90 5
91 1
92 2
93 3
95 7
96 2
97 2
98 8
99 8
1...

output:

80
68
31
39
42
89
31
82
43
49
90
69
52
64
80
49
67
58
85
37
65
69
78
44
49
64
86
42
36
73
29
62
72
7
52
56
74
19
43
49
46
35
72
54
30
41
76
74
46
79
65
85
35
21
72
22
86
37
66
52
56
27
45
58
55
68
27
83
25
40
63
58
34
59
5
41
34
73
62
54
86
72
82
58
38
37
44
47
88
67
61
23
81
82
30
83
56
86
80
78
65...

result:

wrong answer 1st lines differ - expected: '81', found: '80'

Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

1277351 1 2000000
2 2
5 1
7 3
8 4
10 1
12 1
15 2
16 1
18 1
22 1
25 1
28 3
29 1
32 1
35 1
36 1
38 2
40 1
41 2
42 1
43 2
44 2
45 1
48 1
49 1
50 2
54 2
55 2
56 1
58 2
59 2
60 2
62 1
66 1
68 3
69 1
70 3
72 2
76 1
78 1
79 2
81 2
82 3
84 2
85 1
86 2
89 1
90 2
91 2
92 1
93 1
96 3
98 3
99 2
100 3
101 1
102 ...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #21:

score: 0
Time Limit Exceeded

input:

5000 5000 2000000
1 1
2 1
3 1
4 1
6 1
7 1
8 1
9 1
10 1
11 1
14 1
15 3
17 2
18 2
21 1
22 1
24 1
25 3
27 1
28 2
29 1
30 1
31 1
32 1
33 1
34 1
35 1
37 1
38 1
39 1
40 2
41 2
43 1
45 1
47 1
49 1
50 1
51 1
54 1
55 1
56 1
61 1
62 2
64 1
65 1
67 2
68 2
70 2
72 2
74 1
76 3
79 2
82 4
83 2
84 1
88 1
91 1
92 1
...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

191299 5000 300000
1 1
5 1
6 2
7 1
8 1
10 1
11 2
12 2
17 1
18 1
19 1
20 1
21 1
22 2
25 1
28 1
29 2
30 1
31 2
34 1
36 1
37 1
38 1
40 1
42 1
43 1
44 1
45 1
47 2
48 1
51 1
53 3
54 2
56 2
58 2
59 2
61 2
63 4
64 2
67 1
68 2
69 2
70 1
72 1
76 1
77 1
78 1
80 2
83 1
84 1
87 1
88 1
89 1
91 2
93 1
95 1
96 1
9...

output:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #41:

score: 0
Time Limit Exceeded

input:

1278949 5000 2000000
4 1
9 1
12 1
13 1
15 2
20 1
21 2
26 1
36 1
39 2
43 1
46 2
59 1
64 1
66 1
71 1
73 1
75 1
78 2
83 1
87 1
89 1
92 1
97 1
103 1
104 1
108 1
111 1
113 1
114 1
117 2
118 1
130 1
137 1
140 1
151 1
152 1
155 1
158 2
163 1
164 1
165 1
168 1
172 1
173 1
183 1
185 1
186 1
192 1
208 1
210 2...

output:


result: