my code has worked on codeblocks and when I send it. it is getting wrong answer on test 1 and the test message form is: " Wrong outout formats (0 elements printed ) unexpected end of file "
any help would be great
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
my code has worked on codeblocks and when I send it. it is getting wrong answer on test 1 and the test message form is: " Wrong outout formats (0 elements printed ) unexpected end of file "
any help would be great
using namespace std; const int N=1e5+5,M=1e4; long long minn=1e18,mux=-1e18; int n,k,cnt=1; const int mod=1e9+7; vectoradj[N],v; int b=0; int vis[N],ans[N], a[N]; void dfs(int node){ vis[node]=1; for(int i=0;i<adj[node].size();i++){ if(vis[adj[node][i]]==0){ ans[adj[node][i]]=max(ans[node]+1,ans[adj[node][i]]); dfs(adj[node][i]); } } } main() { int n; cin>>n; for(int i=0;i<n-1;i++){ int x,y; cin>>x>>y; adj[x].pb(y); adj[y].pb(x); } for(int i=1;i<=n;i++) cin>>a[i]; dfs(1); int b=0; for(int i=2;i<=n;i++) if(ans[a[i]]<ans[a[i-1]]) b=1; if(b==1) cout<<"No"<<endl; else cout<<"Yes"<<endl; return 0; }
Hi..
Given an array a that containes 2n elements each element has han an occurrence of 2 in the array.
so {1,2,4,1,4,2} would be an example, Now we have Q queries each query is asking for the maximum element on the segment L...R,but if the element has 2 occurrences on the segment L...R it will not be counted.
so if a={1,2,4,1,4,2} and query={2,6} the answer will be 1 because 4 and 2 will not be counted.
I think I can solve this uning Mo algorithm but I want a segment tree aproach.
Any help would be great, Thank you for reading.
There is a tree that consists of one node(the root) let it be (1).
There is some queries each query is either
find if x is ancestor of y.
make x a son of y(its guaranteed that y exist).
If the first query does not exist its easy to solve it using DFS but I am stuck at finding a solution for the whole problem.
How to solve this?
Example : {1,2,2,3,3}
the answer here is 5 :
{1,2,2} {1,2,3} {1,3,3} {2,2,3} {2,3,3}
I want a formula to calculate this.
I searched through Internet but I did not find a clear answer.
I am not good at math so I want a simple explination If that is possible. Thank you.
hey... so I am learning about segment tree and I am wondring if It can solve this proplem that I came up with : given an array and some queries each query is a segment from index L to index R and the answer to the query is a[l]*1 + a[l+1]*2 + a[l+2]*3 +.... a[r]*(r-l+1) Is it possible to solve this proplem using segment tree and how? I am happy to see your opinions about this. Thank you for reading.
Name |
---|