Submission #54581

#TimeUsernameProblemLanguageResultExecution timeMemory
54581ikura355Fortune Telling 2 (JOI14_fortune_telling2)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int n,m; int a[maxn], b[maxn], c[maxn]; int pos[maxn], res[maxn]; vector<int> p[maxn]; int sz; int limit, tree[maxn*9]; int fen[maxn*3]; map<int,int> mp; int rec[maxn*3]; void cpidx() { for(int i=1;i<=n;i++) mp[a[i]], mp[b[i]]; for(int i=1;i<=m;i++) mp[c[i]]; for(auto &it : mp) { it.second = ++sz; rec[sz] = it.first; } for(int i=1;i<=n;i++) a[i] = mp[a[i]], b[i] = mp[b[i]]; for(int i=1;i<=m;i++) c[i] = mp[c[i]]; } void init() { limit = 1; while(limit<=sz) limit*=2; } void update(int x, int val) { x += limit; tree[x] = max(tree[x], val); while(x) { x/=2; tree[x] = max(tree[x<<1], tree[x<<1|1]); } } int query(int l, int r) { l += limit; r += limit; int res = 0; while(l<r) { if(l%2!=0) res = max(res, tree[l++]); if(r%2==0) res = max(res, tree[r--]); l/=2; r/=2; } if(l==r) res = max(res, tree[l]);o return res; } void add(int x, int val) { while(x) { fen[x] += val; x -= x&-x; } } int sum(int x) { int res = 0; while(x<=sz) { res += fen[x]; x += x&-x; } return res; } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]); for(int i=1;i<=m;i++) scanf("%d",&c[i]); cpidx(); init(); for(int i=1;i<=m;i++) update(c[i], i); for(int i=1;i<=n;i++) { pos[i] = query(min(a[i],b[i]), max(a[i],b[i])-1); p[pos[i]+1].push_back(i); } for(int i=m;i>=1;i--) { add(c[i],1); for(auto x : p[i]) res[x] = sum(max(a[x], b[x])); } long long ans = 0; for(int i=1;i<=n;i++) { // printf("%d : pos = %d res = %d\n",i,pos[i],res[i]); if(pos[i]==0) { if(res[i]%2==0) ans += rec[a[i]];//, printf("%d ",rec[a[i]]); else ans += rec[b[i]];//, printf("%d ",rec[b[i]]); } else { if(res[i]%2==1) ans += rec[min(a[i], b[i])];//, printf("%d ",rec[min(a[i], b[i])]); else ans += rec[max(a[i], b[i])];//, printf("%d ",rec[max(a[i], b[i])]); } } printf("%lld",ans); }

Compilation message (stderr)

fortune_telling2.cpp: In function 'int query(int, int)':
fortune_telling2.cpp:48:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(l==r) res = max(res, tree[l]);o
     ^~
fortune_telling2.cpp:48:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     if(l==r) res = max(res, tree[l]);o
                                      ^
fortune_telling2.cpp:48:38: error: 'o' was not declared in this scope
fortune_telling2.cpp:50:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
fortune_telling2.cpp:67:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:68:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=m;i++) scanf("%d",&c[i]);
                           ~~~~~^~~~~~~~~~~~