Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_rotated #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# libcompetitive

A C++ header-only library with snippets useful for Competitive Programming.
A C++ header-only library with snippets useful (and not only) for Competitive Programming.

## Example usage

Expand Down
19 changes: 19 additions & 0 deletions include/libcompetitive.hxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdio>
#include <vector>

inline int parseint(void) {
int c, n;
Expand All @@ -10,3 +11,21 @@ inline int parseint(void) {

return n;
}

template <typename T, typename A>
inline bool is_rotated(std::vector<T, A> const& v) {
int rises = 0;
int falls = 0;
for (size_t i = 0, s = v.size(); i < s; i++) {
if (v[i] < v[(i + 1) % s]) {
rises++;
}
if (v[i] > v[(i + 1) % s]) {
falls++;
}
if (rises > 1 && falls > 1) {
return false;
}
}
return true;
}