CodeForces 622C Not Equal on a Segment
来源:互联网 发布:为什么江老是被黑 知乎 编辑:程序博客网 时间:2024/06/03 16:01
利用一个辅助数组存序号就行了。
#include <iostream>#include <cstdio>const int MAX = 2e5 + 5;int arr[MAX];int pre[MAX];int main(){int n, q;scanf("%d%d", &n, &q);for (int i = 1; i <= n; ++i){scanf("%d", &arr[i]);if (arr[i] == arr[i - 1])pre[i] = pre[i - 1];elsepre[i] = i;}/*for (int i = 1; i <= n; ++i){printf("%d ", pre[i]);}puts("");*/int st, ed, val;for (int i = 0; i != q; ++i){scanf("%d%d%d", &st, &ed, &val);if (arr[ed] == val && pre[ed] == pre[st])printf("-1\n");else{if (arr[ed] != val)printf("%d\n", ed);elseprintf("%d\n", pre[ed] - 1);}}return 0;}
0 0
- Codeforces 622 C. Not Equal on a Segment
- CodeForces 622 C. Not Equal on a Segment(水~)
- CodeForces 622C Not Equal on a Segment
- CodeForces 622C Not Equal on a Segment
- Codeforces 622C Not Equal on a Segment
- CodeForces 622C F - Not Equal on a Segment
- Educational Codeforces Round 7--C. Not Equal on a Segment
- Educational Codeforces Round 7 C. Not Equal on a Segment
- Educational Codeforces Round 7-C. Not Equal on a Segment
- Not Equal on a Segment CodeForces
- Not Equal on a Segment CodeForces
- Not Equal on a Segment CodeForces
- Not Equal on a Segment CodeForces
- Codeforces 622C Not Equal on a Segment 【线段树 or dp】
- Codeforces 622C Not Equal on a Segment(线段树)
- CodeForces 622C Not Equal on a Segment(并查集)
- Codeforces 622C Not Equal on a Segment 【线段树 Or DP】
- 7_6_S题 Not Equal on a Segment题解 [codeforces 622C] (贪心)
- 算法题9 动态规划之最长公共子序列&最长公共子串
- 死锁、活锁、优先级翻转
- 算法题10 最长等差序列问题
- Android 中 onTouch 和OnClick 冲突的处理(onTouchEvent返回true时与onclick冲突)
- 算法题11 字符串的所有对称子串
- CodeForces 622C Not Equal on a Segment
- 算法题12 数组中所有的逆序对
- Android设计模式系列(2)--SDK源码之观察者模式
- 算法题13 排序算法(更新快排)
- iOS单元测试
- 算法题14 最低公共祖先
- 数据仓库专题20-案例篇:电商领域数据主题域模型设计v0.1(改进意见征集中)
- android 反编译
- android触摸事件传递